我有一个远程存储库,我已从该存储库中提取并从中分支。我想让新分支与 master 所做的更改保持同步。我正在考虑下面的工作流程,它是否有意义或者是否有更好的方法来做到这一点?
-
初始分支和结账:
git checkout master
git pull
git checkout -b my_branch
-
做一些工作my_branch
,然后定期:
git checkout master
git pull
git checkout my_branch
git merge master --no-ff
根据需要重复步骤 2,定期推送到遥控器my_branch
.
然后当准备好合并回来时:
git checkout master
git merge my_branch --no-ff
听起来还好吗?
您可以简化您的命令:
1.
git fetch
git checkout -b my_branch origin/master
2.
git fetch
git merge origin/master
git fetch
更新您的远程分支,当您不打算在该分支上工作时,通常不需要拥有该分支的本地副本。
您可以省略--no-ff
设置后git config --global merge.ff false
.
git help config
says:
merge.ff
By default, Git does not create an extra merge commit when merging
a commit that is a descendant of the current commit. Instead, the
tip of the current branch is fast-forwarded. When set to false,
this variable tells Git to create an extra merge commit in such a
case (equivalent to giving the --no-ff option from the command
line). When set to only, only such fast-forward merges are allowed
(equivalent to giving the --ff-only option from the command line).
意识到git pull
只是一个组合git fetch
and git merge
.
通常你只是想要git pull --rebase
这本质上是git fetch
plus git rebase
,并创造了更加清晰的历史。
您的“定期推送”有什么原因吗?如果没有其他人在同一个分支上工作,那就完全没问题,只需在完成所有操作后进行推送即可。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)