Guide to Git

– Install git and create a GitHub account

The first two things you’ll want to do are install git and create a free GitHub account.

Follow the instructions here to install git (if it’s not already installed). Note that for this tutorial we will be using git on the command line only.

Once you’ve done that, create a GitHub account here.

– Create a local git repository

When creating a new project on your local machine using git, you’ll first create a new repository (or often, ‘repo‘, for short).

create a new directory, open it and perform a
git init
to create a new git repository.

– Add a new file to the repo

You can propose changes (add it to the Index) using
git add <filename>
git add *
This is the first step in the basic git workflow. To actually commit these changes use
git commit -m "Commit message"
Now the file is committed to the HEAD, but not in your remote repository yet.

– Checkout a repository

create a working copy of a local repository by running the command
git clone /path/to/repository
when using a remote server, your command will be
git clone [email protected]:/path/to/repository

– Branches

create a new branch named “feature_x” and switch to it using
git checkout -b feature_x
switch back to master
git checkout master
and delete the branch again
git branch -d feature_x
a branch is not available to others unless you push the branch to your remote repository
git push origin <branch>

– Check changes

Check the file that were changed by running the command
git status
To compare the actual change with the original file  by running the command
git diff /path/to/file

 

Scroll to Top