Git is a version control and code management system. The source code for all the programming assignments and the course project will be submitted through Git. Note: You will only need basic Git information for this class. If you are interested in becoming a power user of Git, there are some resources at the bottom of this page. Forward any questions on Git to the TA. We will be going over Git usage in the TA session. A quick reference to Git commands is available at: http://jonas.nitro.dk/git/quick-reference.html There is a central repository from which you will make a clone on your local machine. You need to create your own directory, put your source files there, and commit them. We will read and grade your code by accessing the repository. ------------------------------------- 1. install Git ------------------------------------- Before we start, ensure that you have Git installed in your system. You can proceed in one of different ways: 1. Git is already installed on linux.cs.duke.edu. You can use git there. 2. You can integrate Git into your favorite IDE. Eclipse+EGit is a good choice (You can also do this in Linux or Windows). See detailed information here: http://www.eclipse.org/egit/ 3. You can use an SSH program with Git. Some of you may be using PuTTY as the SSH program. You can take a look on how to add Git support in PuTTY here: http://nathanj.github.com/gitguide/tour.html 4. If you are running Ubuntu or Debian Linux on your own machine, you can install Git by: apt-get install git-core This command needs administrative privileges to run, and will not work on all Linux distributions. Please go to the package manager of your own Linux system to install Git. For example, yum is used in Fedora Linux. ******************************************************************************************** What you will see below are commands in Linux, which can be run as is on linux.cs.duke.edu ******************************************************************************************** ---------------------------------- 2. initial setting --------------------------------- - configure user properties: git config --global user.name "FirstName LastName" [replace FirstName and LastName with your real names] git config --global user.email "user@your_email" [replace user@your_email with your email address] - setup color git config --global color.branch "auto" git config --global color.status "auto" git config --global color.diff "auto" [Reminder: The commands above are one-time settings. So you won't need to worry about them after you set them once.] ------------------------------- 3. start using Git ------------------------------- - Make a directory for CPS 216 work on the machine where git is installed (e.g., linux.cs.duke.edu or your local machine). I make a directory like this: mkdir ~/cps216_assignments - Go to that directory you just created (~/cps216_assignments in my case). cd ~/cps216_assignments - Make a clone from the central git repository git clone ssh://USERNAME@linux.cs.duke.edu/usr/research/proj/git/cps216/USERNAME.git [replace USERNAME with your user name] - You should find a new directory named after your username. Go into that directory (~/cps216_assignments/gang in my case). cd ~/cps216_assignments/USERNAME [replace USERNAME with your user name] - Make a directory for assignment 1 inside that directory mkdir assignment1 - Make a directies for Part A, Part B, Part C etc. inside the assignment directory mkdir -p assignment1/parta mkdir -p assignment1/partb mkdir -p assignment1/partc [and so on] - start putting your source files in the directory for assignment 1 (~/cps216_assignments/gang/assignment1 in my case). cp /path/to/partAMap.java ~/cps216_assignments/USERNAME/assignment1/parta cp /path/to/partAReduce.java ~/cps216_assignments/USERNAME/assignment1/parta cp /path/to/partADriver.java ~/cps216_assignments/USERNAME/assignment1/parta cp /path/to/programPartB.java ~/cps216_assignments/USERNAME/assignment1/partb [and so on] - let Git know that you have added those new files. git add is recursive, and so the "git add ." command will add all new files in the current directory and its subdirectories cd ~/cps216_assignments/USERNAME git add . - Note: if you want to add one new file only, then use "git add " - now you need to commit your changes git commit -m "Any_Message" -a [Any_Message is a log message that you will enable you to later understand what high-level changes you made in this commit. This message will appear in the log. For example, "Any_Message" may be "Fixed a nasty memory leak in the WordCount mapper"] - it is a good idea to commit changes in regular intervals rather than waiting until the end. By doing so, you will get all the advantages of a source code repository, e.g., undoing incorrect changes. Note however that git commit will NOT push your changes back to the central repository. You need the following git push command for that. - push all your changes back to the repository (so that we can see them). Note: do not forget this step git push Sometimes you may run into this error: ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'ssh://gang@linux.cs.duke.edu/usr/research/proj/git/cps216.git' To prevent you from losing history, non-fast-forward updates were rejected Merge the remote changes before pushing again. See the 'Note about fast-forwards' section of 'git push --help' for details. This happens because someone or youself made some changes from other clients and the code in the current client is out of date. If so, please update you local clone by this command: git pull then try "git push" again - If you or your project partner wants to work on the same repository from a different machine (say, your laptop in addition to using linux.cs.duke.edu), then you can make a clone on that machine using git clone, and then use git pull to get the latest version of the code that was checked in using git push. Basically, git pull is the counterpart to git push. ----------------------------- 4. other notes ----------------------------- - "git add", "git commit" and "git push" will be the most frequent commands you will be using. - if you want to copy files between different machines/clusters. You can use scp. Assume you want to copy a file named FILE from your home directory at linux.cs.duke.edu to current directory in your local machine, use this command. scp USERNAME@linux.cs.duke.edu:~/FILE ./ Replace USERNAME with your user name. Likewise, if you want to copy a file named FILE in the current directory in your local machine to your home directory at linux.cs.duke.edu, use this command: scp ./FILE USERNAME@linux.cs.duke.edu:~/ - sometimes you may want to pack lots of files/directories into one file (similar to .zip or .rar files in windows), use this command: tar -zcvf FILENAME.tar.gz DIR FILENAME could be any name meaningful to you. DIR is the directory you want to pack. To unpack, use this command: tar -zxvf FILENAME.tar.gz you will get DIR and all the files within it in your current directory. ----------------------------- 5. more Git resources ----------------------------- - A quick reference to Git commands: http://jonas.nitro.dk/git/quick-reference.html - Getting to Grips with Git (a collection of techniques, tips, and tools that make version control with Git a breeze): http://www.viget.com/extend/getting-to-grips-with-git/ - Eclipse+EGit: http://www.eclipse.org/egit/ - Effectively Using Git With Subversion: http://www.viget.com/extend/effectively-using-git-with-subversion/ - Git support in PuTTY (SSH): http://nathanj.github.com/gitguide/tour.html