go back


Git is a version-control system that is used for tracking changes in source code. It can be used to track changes, coordinate work with others, and test branches before publishing. Git commands are ran from the command line inside of

git areas

Getting started with Git

To get started with Git, you first need to download it to your computer from here:
Git Download Page

You will also need to create a free GitHub account here:

And then use these to learn how to use Git:
Git Explorer
Learn Git Branching
Git Cheat Sheet

git cheat sheet

Configure Git Information

Configure user information for all local repositories

$ git config --global user.name "[name]"

‐ Sets the user name you want attached to your commits.

$ git config --global user.email "[email address]"

‐ Sets the email you want attached to your commits.

$ git config --global color.ui auto

‐ Enables helpful colorization of command line output.

$ git command --help

‐ Outputs a list of git commands.

Create a Repository

Starting a project only needs to be done once, either locally with git init or by cloning an existing repository.

$ git init

‐ Starts a git repository in an existing directory.

$ git clone [url]

‐ Downloads/clones a repository from GitHub.

Ignore File

If a specific file or file types should not be added to a git repository, a file named .gitignore tracks files that should be ignored.

$ touch .gitignore

Some helpful templates and common .gitignore files can be found here: Git Ignore Templates

Working with Branches

Branches are a way to separate your main code base from the code you are working on new content in. You can "check out" a branch to switch over and avoid pushing untested code into publication. Master is the main branch that is started on. Use git status to see what branch you are currently using.

$ git status

‐ Check to see which branch you are currently on.

$ git branch [branch-name]

‐ Creates a new branch.

$ git checkout [branch-name]

‐ Switches to a different branch.

$ git checkout -b [branch-name]

‐ Combines git branch and git checkout into one command. It creates a new branch and switches to it.

$ git merge [branch-name]

‐ Combines the named branch history into your current working branch. Usually done in pull requests.

$ git branch -d [branch-name]

‐ Deletes the named branch.

Make a change

Add and commit any changes you have made to the local repositiory before you push to the remote one.

$ git add [file]

‐ Stages a single file and is ready to be commited.

$ git add .

‐ Stages all changed files and is ready to be commited.

$ git commit -m "commit message"

‐ Commits all staged files with a message about changes made.

$ git reset [file]

‐ Unstages a single file, but keeps changes made to the file.

$ git reset --hard

‐ Revert everything to the last commit.

Sync changes

To make sure your local copy is the same as the remote repository, it is important to remember to synchronize your files with these commands.

$ git fetch

‐ Downloads all of the branch history and updates, but your local copies stay the same. Does not merge like git pull.

$ git merge

‐ Combines remote tracking branch into current local branch.

$ git pull

‐ Downloads and updates your local copy with all new commits from the remote branch. It is a combination of git fetch and git merge.

$ git push

‐ Uploads all current local changes added and commited to the GitHub repository.

$ git push origin [branch-name]

‐ The origin represents a remote name where you want to push changes

git cheat sheet