一、新建代码库
$ git init
$ git init <project_name>
$ git clone <project_url>
二、配置git
$ git config --list
$ git config -l
$ git config --global -e
$ vim .gitconfig
$ git config --global user.name <name>
$ git config --global user.email <email>
三、增加(追踪)、删除文件
$ git add <files...>
$ git add ./
$ git add <dir>
$ git add -p
$ git rm <files...>
$ git rm --cached <file>
$ git mv <oldfile> <newfile>
四、代码提交
$ git commit -m <message>
$ git commit <files...> -m <message>
$ git commit -a
$ git commit -v
$ git commit --amend -m <message>
$ git commit --amend <files...>
五、分支
$ git branch
$ git branch -r
$ git branch -a
$ git branch <new branch>
$ git checkout -b <new branch>
$ git branch <branch> <commit>
$ git branch --track <branch> <remote branch>
$ git checkout <branch>
$ git checkout -
$ git branch --set-upstream <branch> <remote branch>
$ git merge <branch>
$ git cherry-pick <commit>
$ git branch -d <branch>
$ git push origin --delete <branch>
$ git branch -dr <remote branch>
六、标签
$ git tag
$ git tag <tag>
$ git tag <tag> <commit>
$ git tag -d <tag>
$ git push origin :refs/tags/<tagname>
$ git show <tap>
$ git push <remote> <tag>
$ git push <remote> --tags
$ git checkout -b <branch> <tag>
七、查看信息
$ git status
$ git log --stat
$ git log -S <keyword>
$ git log <tag> HEAD --pretty=format:%s
$ git log <tag> HEAD --grep feature
$ git log --follow <file>
$ git whatchanged <file>
$ git log -p <file>
$ git log -5 --pretty --oneline
$ git shor tlog -sn
$ git blame <file>
$ git diff
$ git diff HEAD
$ git diff <first branch> <second branch>
$ git diff --shortstat "@{0 day ago}"
$ git show <commit>
$ git show --name-only <commit>
$ git show <commit>:<filename>
$ git reflog
八、远程同步
$ git fetch <remote>
$ git remote -v
$ git remote show <remote>
$ 增加一个新的远程仓库,并命名
$ git remote add <remote> <url>
$ git pull <remote> <branch>
$ git push <remote> <branch>
$ git push <remote> --force
$ git push <remote> --all
九、撤销
$ git checkout <file>
$ git checkout <commit> <file>
$ git checkout .
$ git reset <file>
$ git reset --hard
$ git reset <commit>
$ git reset --hard <commit>
$ git reset --keep <commit>
$ git revert <commit>
$ git stash
$ git stash pop