一、新建分支及查看
git branch <local_branch>
git checkout -b <local_branch>
git branch
git branch -a
二、删除分支
git branch -d <local_branch>
git branch -r -d origin/<remote_branch>
三、追踪远程分支
git clone <git_url>
git checkout --track origin/<remote_branch>(适用于本地无分支)
git push --set-upstream origin <remote_branch>(适用于远程无分支)
git checkout -b <local_branch> origin/<remote_branch>(适用于本地无分支)
git branch --set-upstream <local_branch> origin/<remote_branch>(适用于本地及远程均有分支)
git branch -u origin/<remote_branch>(适用于本地和远程均有分支, 设置当前分支)
git branch --set-upstream-to=origin/<remote_branch>(适用于本地远程均有,设置当前分支)
git branch --unset-upstream master(取消之前的追踪)
git branch -vv
四、远程分支合并
git checkout <local_branch>
git pull origin <remote_branch>
git checkout master
git merge <local_branch>
五、本地有改动pull
git stash
git stash save <msg>
git pull
git stash show
git stash list
git stash pop
git stash apply stash@{num}
git stash drop stash@{num}
(备份本地修改文件, 删除修改部分, pull, 增加修改部分)
(.git/refs/stash最后一个stash节点对应的指针, .git/log/refs/stash全部节点对应指针)
(WIP: work in progress)
六、git 回退
git log
git reset --hard <commit_id>
七、git配置信息
git config --list(-l)
git config user.name
git config user.email
git config --global user.name <your_name>
git config --global user.email <your_email>
git config --global --replace-all user.name <your_name>
git config --global --replace-all user.email <your_email>
git config --global --unset <field_name>
八、本分支删除另一分支在本分支的文件
git rm --cached <file-name> <dir-name> -rf
rm <file-name> <dir-name> -rf