git branch -r
-
创建并在本地跟踪远程分支
git branch <new_branch_name> <remote_branch_name>
git checkout <new_branch_name>
-
在本地创建新分支并提交到远程
git branch 分支名
git checkout 分支名
git push -u origin 分支名
或者简写
git checkout -b 分支名
git push -u origin 分支名
关联命令行 可执行可不执行,不影响开发
git branch --set-upstream-to=origin/新建的分支名
// 关联前
git pull origin 分支名 / git push origin 分支名
// 关联后
git pull 分支名 / git push 分支名
-
在主分支拉取新分支开发,开发结束再合并到主分支
# 基于master分支新建一个分支
git checkout -b new-feature masetr
# 在新分支上做一些修改
git add <file>
git commit -m "Finish a feature"
# 合并新分支到主分支
git checkout master
git merge new-feature
# 删除新分支
git branch -d new-feature
-
在主分支拉取新分支开发,主分支也有修改,开发结束再合并到主分支
#开一个新分支
git checkout -b new-feature master
# 编辑文件并提交
git add <file>
git commit -m "Finish a feature"
# 在主分支上开发
git checkout master
# 编辑文件并提交
git add <file>
git commit -m "Make some super-stable changes to master"
# 合并新分支
git merge new-feature
git branch -d new-feature