Author: David Montaño
Git is a fast, scalable, distributed revision control system with an unusually rich command set that provides both high-level operations and full access to internals.
Works with ssh or git protocol (git daemon listens on port 9418)
$ tar xzf project.tar.gz
$ cd project
$ git init
$ git add .
$ git commit
$ git add file1 file2 file3
$ git diff --cached
$ git status
On branch master
Changes to be committed:
Your branch is up-to-date with 'origin/master'.
(use "git reset HEAD <file>..." to unstage)
modified: file1
modified: file2
modified: file3
$ git commit
$ git commit -a
Many revision control systems provide an add command that tells the system to start tracking changes to a new file. Git’s add command does something simpler and more powerful: git add is used both for new and newly modified files, and in both cases it takes a snapshot of the given files and stages that content in the index, ready for inclusion in the next commit.
$ git log
$ git log -p
$ git log --stat --summary
$ git branch experimental
$ git branch
experimental
* master
$ git checkout experimental
# (edit file)
$ git commit -a
$ git checkout master
# (edit file)
$ git commit -a
$ git merge experimental
$ git diff
# (resolve conflicts)
$ git commit -a
$ gitk
$ git branch -d experimental
$ git branch -D crazy-idea
bob$ git clone /home/alice/project myrepo
# (edit files)
bob$ git commit -a
# (repeat as necessary)
alice$ cd /home/alice/project
alice$ git pull /home/bob/myrepo master
alice$ git fetch /home/bob/myrepo master
alice$ git log -p HEAD..FETCH_HEAD
alice$ gitk HEAD..FETCH_HEAD
alice$ gitk HEAD...FETCH_HEAD
alice$ git remote add bob /home/bob/myrepo
alice$ git fetch bob
alice$ git log -p master..bob/master
alice$ git merge bob/master
alice$ git pull . remotes/bob/master
bob$ git pull
bob$ git config --get remote.origin.url
/home/alice/project
bob$ git branch -r
origin/master
bob$ git clone alice.org:/home/alice/project myrepo
$ git log
commit c82a22c39cbc32576f64f5c6b3f24b99ea8149c7
Author: Junio C Hamano <junkio@cox.net>
Date: Tue May 16 17:18:22 2006 -0700
merge-base: Clarify the comments on post processing.
$ git show c82a22c39cbc32576f64f5c6b3f24b99ea8149c7
$ git show c82a22c39c # the first few characters of
# the name are usually enough
$ git show HEAD # the tip of the current branch
$ git show experimental # the tip of the "experimental" branch
$ git show HEAD^ # to see the parent of HEAD
$ git show HEAD^^ # to see the grandparent of HEAD
$ git show HEAD~4 # to see the great-great grandparent of HEAD
$ git show HEAD^1 # show the first parent of HEAD (same as HEAD^)
$ git show HEAD^2 # show the second parent of HEAD
$ git tag v2.5 1b2e1d63ff
$ git diff v2.5 HEAD # compare the current HEAD to v2.5
$ git branch stable v2.5 # start a new branch named "stable" based
# at v2.5
$ git reset --hard HEAD^ # reset your current branch and working
# directory to its state at HEAD^
$ git grep "hello" v2.5
$ git grep "hello"
$ git log v2.5..v2.6 # commits between v2.5 and v2.6
$ git log v2.5.. # commits since v2.5
$ git log --since="2 weeks ago" # commits from the last 2 weeks
$ git log v2.5.. Makefile # commits since v2.5 which modify
# Makefile
$ git daemon --base-path=. --export-all --enable=receive-pack --reuseaddr --informative-errors --verbose