Getting started with Git

W4118 Fall 2012


Git is a version control system that Linux hackers use. If you don't know git, you probably want to start by reading the official git documentation

First you need to install the provided SSH key pair (mailed to you on your UNI@columbia.edu email) in the ~/.ssh directory to be able to authenticate to the repository server. Then, you will need to clone your own homework repository to start working on it (replace UNI by your own UNI):

$ git clone gitosis@os1.cs.columbia.edu:UNI/hmwk1
Initialized empty Git repository in /root/hmwk1/.git/
Receiving objects: 100% (3/3), done.
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)

Before doing any commits, you need to configure git. Create (or edit) the file ~/.gitconfig with the following content

[user]
        name = Nicolas Viennot
        email = nicolas@viennot.biz
[color]
        diff = auto
        status = auto
        branch = auto
[push]
        default = matching

Your typical workflow:

$ git diff # see what you 
$ git add file1 file2
$ git diff --cached # see what you are about to commit
$ git commit # explain what you did on file1 file2
... a few commits later ...
$ git push # upload your changes on the repository
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 222 bytes, done.
Total 2 (delta 0), reused 0 (delta 0)
The deadline is in 14 days, 23 hours, 57 minutes, 49 seconds
To git+ssh://os1/git/testos1/hmwk1
   34f170a..f760521  master -> master

If git asks you for a password whenever you try to do a clone/push/pull/fetch then you need to make sure that your ~/.shh/ directory looks like this:

root@os1 ~ $ ls -lh .ssh
-rw------- 1 root root 672 Aug 17 2007 id_dsa
-rw-r--r-- 1 root root 604 Aug 17 2007 id_dsa.pub

If you already use ssh keys for logging into other servers or git repositories, you can save the private/public keypair that was mailed to you as ~/.ssh/id_dsa_os and ~/.ssh/id_dsa_os.pub and create the file ~/.ssh/config like this:

$ touch ~/.ssh/config
$ chmod 600

Then open the file and input this data:
Host os1.cs.columbia.edu
	IdentityFile ~/.ssh/id_dsa_os
	User gitosis


Checking your submissions

Once you have submitted your homeworks we strongly recommend that your re-clone the submission to your machine to check that what we have received is in fact what you intented to submit.

The procedure for doing so would be the following (replace N with the homework number, e.g. 1):

pushd /tmp
$ git clone gitosis@os1.cs.columbia.edu:UNI/hmwkN.git
$ cd hmwkN
# ... check contents of directory
$ cd ..
$ rm -rf hmwkN
$ popd