Getting Help:
$ git help <verb>
Your Configure:
$ git config --list
$ git config --global user.name "[name]"
$ git config --global user.email "[email address]"
$ git config --global user.name "[another name]"
Getting a Git Repository:
$ git init [project-name]
$ git clone [url] [project-name]
Ignoring Files:
# no .a files
*.a
# but do track lib.a, even though you're ignoring .a files above
!lib.a
# only ignore the root TODO file, not subdir/TODO
/TODO
# ignore all files in the build/ directory
build/
# ignore doc/notes.txt, but not doc/server/arch.txt
doc/*.txt
# ignore all .txt files in the doc/ directory
doc/**/*.txt
$ git update-index --assume-unchanged path/to/file
Untrack Files:
$ git rm -r --cached .
$ git add .
$ git commit -m "untrack some files"
Checking the Status of Your Files:
$ git status
Tracking New Files:
$ git add [file]
$ git add .
Viewing Your Staged and Unstaged Changes:
$ git diff
$ git diff --staged
The Git repository browser
$ gitk
Committing Your Changes:
$ git commit -m "[descriptive message]"
$ git commit -a -m "[descriptive message]"
Removing Files:
$ git rm [file]
$ git rm --cached [file]
$ git mv [file-original] [file-renamed]
Viewing the Commit History:
$ git log
git log --follow [file]
$ git log -p -2
$ git log --pretty=format:"%h - %an, %ar : %s"
$ git log --pretty="%h - %s" --author=gitster --since="2008-10-01" --before="2008-11-01" --no-merges -- directory/
$ git show [commit]
$ git diff [first-branch]...[second-branch]
Undoing Things:
$ git commit --amend
$ git commit --amend -m "<right message>"
git push --force-with-lease <repository> <branch>
$ git reset --soft HEAD^
$ git commit -a -c ORIG_HEAD
$ git unstage <file>
$ git reset --hard HEAD~1
$ git checkout -- <file>
Working with Remotes:
$ git remote -v
$ git remote add [bookmark] [url]
$ git remote update [bookmark]
$ git remote set-url origin [url]
$ git fetch [bookmark]
$ git merge [bookmark]/[branch]
$ git push [alias] [branch]
$ git pull
Basic Branching and Merging:
$ git branch
$ git branch [branch-name]
$ git checkout [branch-name]
$ git checkout -- -[branch-name]
$ git checkout -b [branch-name]
$ git merge [branch-name]
$ git branch --no-merged
$ git branch -d [branch-name]
$ git checkout -b [branch-name] origin/[branch-name]
$ git push origin :[branch-name]
Stashing and Cleaning:
git stash
$ git stash pop
$ git stash list
$ git stash drop
Tagging:
$ git tag
$ git tag v1.4
$ git show v1.4
$ git push origin v1.4
$ git push origin --tags
Remove file from all previous commits but keep it locally:
$ git rm --cached <file>
see more: Pro Git book,GIT CHEAT SHEET