By Group 6: Sina Karimi, Ryan Campbell, and Hector Nunez

How To Set-up Git on Your ECE Account

 

What is Git?

Starting your code for the design project? It is extremely useful to use some sort of Version Control System (VCS) when coding. Popular VCSs include Perforce, Git, SVN, CVS, etc.

Some of the main advantages of using a VCS include:

 

- Having a central location that always has the latest code

- Being able to track and easily roll back changes

 

Since we don't have rights on the lab machines most of these options are out. We chose Git since it's free, easy to use, and we were able to set it up under the unix environment without needing any extra permissions. Also, since the ece account is mapped to the windows machines, you can easily use all the provided editors like MULTI and NotePad++.

 

Step1: Login to your ECE account

 

Use PuTTY to login to your ece account using login.ece.ualberta.ca

 

Step2: Getting the source

 

Click here to get the version of git that we used or click here to download the latest from the Git offical website and save the tar file on your ECE account. Or you get it by doing the following in command line:

 

$ wget http://kernel.org/pub/software/scm/git/git-1.7.0.tar.bz2

 

Step3: Untar

 

Create a git folder in your home directory and move the file there.

 

$ mkdir ~/Git
$ mv git-1.7.0.tar.bz2 ~/Git/.
$ cd ~/Git/
$ tar xvf git-1.7.0.tar.bz2

 

Step4: Compiling and installing

 

Compile the Git code by runnig the following commands. This will install the git binaries to your ~/bin folder

 

$ cd git-1.7.0/
$ ./configure --prefix=$HOME
$ make
$ make install

 

Step5: including your bin folder to the $PATH permanently

 

By default the ~/bin directory is not in the $PATH variable. you need to include this path.

 

$ echo "export PATH=$PATH:~/bin/" >> .bash_profile

 

Step6: logout and log back in.

 

you need to logout and then log back in to your account so that the changes in .bash_profile take effect.

 

 

Git Quick-start

 

There is a ton of information on how to use Git available here, but here is a quick guide tailored for our use:

If you have a remote machine that you can use to host you repo follow the Creating a Remote Repository step. If not, there are several free git hosting sites such as github.com where you can sign up for a free hosted git repository.

 

Creating a Remote Repository (i.e. remote.example.net)

use the following commands to initialize your repository.

 

$ ssh you@remote.example.net #you need to provide the password
you@remote:$ mkdir gitRepo #create this directory where ever you want your repo to be on your remote machine
you@remote:$ cd gitRepo
you@remote:$ git init --bare --shared #you need to have git installed on your remote machine as well. you can reuse the steps above.
you@remote:$ exit

 

Add your Project to the Remote Repository

We can now add our existing project to remote git repository. From login.ece.ualberta.com, go to your project directory:

 

$ cd CMPE490/Project
$ git init #initialize this directory as a git repository
$ git add . #add everything in the directory to the repo
$ git commit -a -m "first git commit" #commit everything
$ git remote add origin ssh://you@remote.example.net/path/to/gitRepo #track the remote repository
$ git push origin master #push your commit to the remote repo (check in)

 

Clone the Remote Repository (check out)

Now anyone can easily check the code out using the following commands (from login.ece.ualberta.ca again)

 

$ git clone ssh://you@remote.example.net/path/to/gitRepo

 

Now you can make changes to the local copy from your Windows mapped drive (i.e. using MULTI or NotePad++)

 

View Changes to Code

Once you have edited your code you can see the changes you have made with the following commands:

 

$ git status #this will show you which files have changed or created (if they were created you have to follow the add instructions to add them)
$ git diff --color # this will show the diffs between your code and the last commit

 

Commit Changes and Check in

To check-in your code to the remote repository, you must first commit the changes you have made to the local copy:

 

$ git commit -a -m "This is the commit message"

To check in your commited changes you have to push them to the origin (remote repository)

 

$ git push origin master #master is the name of the local branch, origin is the name of the remote repository (unless changed, the names are always origin and master)

 

View Commit Log

To view a list of the commits made to the repository, you can check the log using:

 

$ git log

 

 

Revert Changes

To roll back to a previous commit:

 

$ git log #to view the commit id you want to roll back to
commit 58fae689d0ecb88174f9e0782a918e5b703531e2
Author: John Doe <jdoe@ece.ualberta.ca>
Date: Fri Mar 5 11:26:39 2010 -0700
 
    This is the commit message
 
 
$ git reset --hard [commit id] #(i.e. 58fae689d0ecb88174f9e0782a918e5b703531e2 from above) Not specifiying a commit ID, will assume last commit id