分支操作
新建分支
git branch查看当前仓库分支列表git branch -v查看每个分支最后一次提交git branch --merged查看已完成合并的分支列表git branch --no-merged查看未完成合并的分支列表git ls-remote <remote> / git remote show <remote>获取远程分支的信息git branch branch-name新建git checkout -b branch-name新建并切换
分支合并
将 branch-1 分支的内容合并到 主分支 (master)
sh
$ git checkout master
$ git merge branch-1将主分支的内容合并到 branch-1 分支
sh
$ git checkout branch-1
$ git merge master合并时出现冲突
sh
$ git merge branch-1
# CONFLICT (content): Merge conflict in index.html
# Automatic merge failed; fix conflicts and then commit the result.
# to fix: 找到发生冲突的文件,解决冲突
$ git commit -m -a 'xxx' # 重新提交合并删除分支
一般来说,完成合并的分支需要及时删除(除非是长期维护的分支)
git branch -d branch-name 删除本地的分支 branch-name
git push origin --delete branch-name 删除远程上的分支 branch-name