My First Git Workflow

This page is a basic introduction to using git for source control. This is in no way a comprehensive guide. There are many ways to do things, especially with git. This is just one way that I chose for its simplicity.


Starting A New Repository

Make a new repository on your prefered hosting service. I recommend github. Some other great options:

Once you create a repository, you need to get the repository's url. It will look something like: Make sure you use a private repository for anything the other students should not be able to see (like most programs).

Now you need to clone the repository:

git clone

Basic Operations

Get Most Recent Changes

git pull

Commit Changes Locally

git add <changed files ...>

git commit -m "Some commit message"

git commit -a -m "Some commit message"

Push Changes to Remote

git push

Reset Most Recent (Non-Committed) Changes

git reset --hard HEAD

Discard Changes to Specific File

git checkout HEAD someFile


Create Branch

git checkout -b newBranchName

Switch Between Branches

git checkout branchName

Get Changes from Master

git checkout branchName

git merge master

Put Change into Master

git checkout master

git merge branchName

Most Common Workflow

git pull

Do some work ...

git add <files ...>

git commit -m "Some useful commit message."

git push

Using Eriq's New Git

The git on the school servers is an older version (1.7.1) and does not let you push using https (the default mode for github). It will give an error like:

error: The requested URL returned error: 403 Forbidden while accessing

fatal: HTTP request failed

To fix this, you can use a version of git that I built from source and host on my school home directory (version 2.8.0 rc2).

You can access this version by running: ~eaugusti/build/git/git

eaugusti@csclnx03:~$ ~eaugusti/build/git/git --version

git version 2.8.0.rc2

To use the new version of git by default, you can add it to your path. To do this, edit the .mybashrc file located in your home directory. (Note that this file is hidden by default, use ls -a to view hidden files.) Add the following lines to the bottom:


export PATH

Afterwards, you need to run the bash command to reload your settings.

eaugusti@csclnx03:~$ bash

To check to make sure you are using the new version, do git --version

eaugusti@csclnx03:~$ ~eaugusti/build/git/git --version

git version 2.8.0.rc2