init 新建
$ git init
$ git init [project-name]
$ git init --bare <directory>
$ git clone [url]
config 配置
$ git config --list
$ git config -e [--global]
$ git config --global user.email
$ git config --global user.name
$ git config --global user.email "MyEmail@gmail.com"
$ git config --global user.name "My Name"
$ git config --global alias.<alias-name> <git-command>
$ git config --system core.editor <editor>
status 状态
$ git status
$ git help status
add 添加
$ git add test.js
$ git add /path/to/file/test.js
$ git add ./*.js
$ git add [file1] [file2] ...
$ git add [dir]
$ git add .
$ git add -p
commit 提交
$ git commit -m [message]
$ git commit [file1] [file2] ... -m [message]
$ git commit -a
$ git commit -v
$ git commit --amend -m [message]
$ git commit --amend [file1] [file2] ...
pull 拉起
$ git pull origin master
$ git pull --no-ff
$ git ci <file>
$ git ci .
$ git ci -a
$ git ci -am "some comments"
$ git ci --amend
push 推送
$ git push [remote] [branch]
$ git push [remote] --force
$ git push [remote] --all
remote 远程管理
$ git fetch [remote]
$ git remote -v
$ git remote show [remote]
$ git remote add [shortname] [url]
$ git remote -v
$ git remote add origin git@ github:xxx/xxx.git
$ git remote set-url origin git@ github.com:xxx/xxx.git
$ git remote rm <repository>
log 信息
$ 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 shortlog -sn
$ git blame [file]
$ git show [commit]
$ git show --name-only [commit]
$ git show [commit]:[filename]
$ git reflog
diff 对比差异
$ git diff
$ git diff --cached [file]
$ git diff HEAD
$ git diff [first-branch]...[second-branch]
$ git diff --shortstat "@{0 day ago}"
$ git diff --staged
$ git diff --cached
$ git diff --stat
branch 分支
$ git branch -a
$ git branch [branch-name]
$ git branch -m [branch-name] [new-branch-name]
$ git branch [branch-name] --edit-description
$ git branch
$ git branch -r
$ git branch [branch-name]
$ git checkout -b [branch]
$ git branch [branch] [commit]
$ git branch --track [branch] [remote-branch]
$ git checkout [branch-name]
$ git checkout -
$ git branch --set-upstream [branch] [remote-branch]
$ git merge [branch]
$ git cherry-pick [commit]
$ git branch -d [branch-name]
$ git push origin --delete [branch-name]
$ git branch -dr [remote/branch]
$ git co <branch>
$ git co -b <new_branch>
$ git co -b <new_branch> <branch>
$ git co $id
$ git co $id -b <new_branch>
$ git br -d <branch>
$ git br -D <branch>
$ git br -v
$ git br --merged
$ git br --no-merged
rm 删除
$ git rm HelloWorld.js
$ git rm /pather/to/the/file/HelloWorld.js
$ git rm [file1] [file2] ...
$ git rm --cached [file]
checkout 检出
$ git checkout
$ git checkout branchName
$ git checkout -b newBranch
reset 撤销
$ 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 revert HEAD
$ git stash
$ git stash pop
$ git stash list
$ git stash apply
$ git stash drop
grep 查找
$ git config --global grep.lineNumber true
$ git config --global alias.g "grep --break --heading --line-number"
$ git grep 'variableName' -- '*.java'
$ git grep -e 'arrayListName' --and \( -e add -e remove \)
merge 合并
$ git merge branchName
$ git merge --no-ff branchName
$ git mv test.js test2.js
$ git mv test.js ./new/path/test.js
$ git mv [file-original] [file-renamed]
$ git mv -f myFile existingFile
tag 标签
$ git tag
$ git tag [tag]
$ git tag [tag] [commit]
$ git tag -d [tag]
$ git push origin :refs/tags/[tagName]
$ git show [tag]
$ git push [remote] [tag]
$ git push [remote] --tags
$ git checkout -b [branch] [tag]