GIT QUICK REFERENCE nassar at renci.org 2/8/2008 FEATURES * Distributed, or centralized * No server needed, no sysadmin support needed, commit privileges not required * Various ways to share changes * Offline * Branching and switching is very convenient * Repository stored in a single .git directory at the top level * Two stage commit, focused on content rather than files * Commits are always local * Imports a cvs or svn repository INSTALLATION * Installs easily from source (for latest version) * Linux: Debian has it in apt-get * Mac: darwinports has it (sudo port install git-core) CONFIGURATION $HOME/.gitconfig: [user] name = Nassib Nassar email = xxx@yyy.zzz [color] status = auto diff = auto branch = auto interactive = auto On the Mac, change fonts in $HOME/.gitk: set mainfont {Monaco 12} set textfont {Monaco 12} set uifont {"Monaco Bold" 12} BASIC COMMANDS * Create a new repository for a project $ cd myproj $ git init (A .git directory is created at the top of the myproj tree.) $ git add . (Contents of all files under . is added to the index.) $ git commit * Clone a repository $ git clone http://www.renci.org/~nassar/vcakec.git (Creates the directory vcakec with a full copy of the repository.) $ cd vcakec * Examine log $ git log $ git log -p (Shows diff.) $ git log --stat (Shows diffstat.) * Examine a commit $ git show [commit_hash] * GUI $ gitk * Commit (in one step, cvs-style) - commit content from all tracked files $ git commit -a (Note: -v option will show diff during commit.) * Commit (staged) - commit content from only specific files $ git add file1 file2 file3 $ git commit * Examine tracking/staging status of files $ git status * Examine uncommitted changes $ git diff (For changes not yet added to index.) $ git diff --cached (For changes already in the index; what would be committed with "git commit".) $ git diff HEAD (For all changes; what would be committed with "git commit -a".) * Set up public repository on web site $ git clone --bare ~/myproj myproj.git $ touch myproj.git/git-daemon-export-ok $ scp -r myproj.git www.renci.org:public_html/ $ ssh www.renci.org -bash-2.05b$ cd public_html/myproj.git -bash-2.05b$ git --bare update-server-info -bash-2.05b$ chmod a+x hooks/post-update -bash-2.05b$ exit * Push commits to public repository $ git push www.renci.org:public_html/myproj.git master BRANCHING AND OTHER COMMANDS $ git branch # list branches $ git branch [b] # create new branch b $ git checkout [b] # switch to branch b $ git checkout -b [b] # create new branch b and switch to it $ git log master..HEAD # show differences between current branch and master $ git rebase master # move branch to master HEAD & replay branch commits $ git checkout master # switch to master $ git merge [b] # merge commits from branch b $ git branch -d [b] # delete branch b if merged $ git branch -D [b] # force delete of branch b (merged or unmerged) $ git checkout -f # revert all local modifications $ git checkout HEAD -- [f] # revert file f to current commit version $ git checkout -- [f] # revert file f to index version