GitFlow分支策略使用问题求助(Bitbucket&SourceTree场景)
GitFlow + Bitbucket 问题解决方案
问题1:Bitbucket中看不到develop分支
你执行git flow init后,本地会生成master和develop分支,但这两个分支并未推送到远程仓库,所以Bitbucket上无法看到。解决步骤:
- 切换到develop分支:
git checkout develop - 推送到远程并设置跟踪关系:
git push --set-upstream origin develop - 同理推送master分支:
git checkout master && git push --set-upstream origin master
问题2:git flow release start/finish时分支基于master而非develop
这是因为远程仓库不存在develop分支,GitFlow优先读取远程基准分支,找不到就会默认使用master。解决方法是先把本地develop推送到远程(参考问题1步骤),之后再执行git flow release start就会基于develop创建分支。
问题3:git flow feature finish feature1时远程拒绝删除分支
错误提示deletion of the current branch prohibited是因为你在Bitbucket中将feature/feature1设为了仓库默认分支,默认分支不允许直接删除。解决方法:
- 登录Bitbucket进入仓库设置,将默认分支改为
master或develop - 回到本地手动删除远程feature分支:
git push origin --delete feature/feature1 - 或者执行
git flow feature finish时加参数跳过远程删除:git flow feature finish --noforce feature1,之后再手动清理远程分支
疑问:完成feature分支开发前还是后推送代码?
- 单人开发:可以开发完成后一次性推送,也可阶段性推送(防止本地代码丢失)
- 多人协作:开发过程中就应定期推送feature分支,方便队友同步代码、避免冲突;合并到develop后,再删除远程的feature分支
适配Bitbucket的GitFlow初始配置流程
- 克隆空仓库后无需执行
git init(克隆操作已创建本地仓库) - 执行
git flow init,按默认选项设置分支前缀 - 推送master和develop到远程:
git checkout master git push --set-upstream origin master git checkout develop git push --set-upstream origin develop
- 后续正常执行feature分支流程:
# 创建feature分支 git flow feature start feature1 # 开发并提交代码 git add . git commit -m "add feature content" # 推送feature分支到远程(协作场景) git push --set-upstream origin feature/feature1 # 完成feature分支合并到develop git flow feature finish feature1 # 推送合并后的develop到远程 git push origin develop
内容的提问来源于stack exchange,提问作者brimri
相关产品推荐
相关产品推荐

