lar*_*ryq 24 git git-merge git-branch
我有一个远程存储库,我已经提取并从中分支出来.我想让新分支保持最新状态,对master进行更改.我正在考虑下面的工作流程,它是否有意义,或者有更好的方法来做到这一点?
初始分支和结帐:
git checkout master
git pull
git checkout -b my_branch
Run Code Online (Sandbox Code Playgroud)做一些工作my_branch,然后定期:
git checkout master
git pull
git checkout my_branch
git merge master --no-ff
Run Code Online (Sandbox Code Playgroud)根据需要重复步骤2,定期推送到遥控器my_branch.
然后准备好合并时:
git checkout master
git merge my_branch --no-ff
Run Code Online (Sandbox Code Playgroud)
听起来不错?
mic*_*has 17
您可以简化命令:
1.
git fetch
git checkout -b my_branch origin/master
Run Code Online (Sandbox Code Playgroud)
2.
git fetch
git merge origin/master
Run Code Online (Sandbox Code Playgroud)
git fetch 更新您的远程分支,当您不打算在此分支上工作时,通常不需要拥有分支的本地副本.
您可以省略--no-ff后设置git config --global merge.ff false.
git help config 说:
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).
Run Code Online (Sandbox Code Playgroud)
要知道,git pull仅仅是一个组合git fetch和git merge.
通常你只想要git pull --rebase哪个本质git fetch上是加号git rebase,并创造一个更清晰的历史.
您的"定期推送"有什么理由吗?如果没有其他人在同一个分支上工作,那就完全没问题了,只需在完成所有事情后再推动.
Chr*_*oph 11
我建议使用rebase工作流程.所以不要使用git pull你应该使用git pull --rebase.
我会对功能分支做同样的事情.所以不是做一个git merge master --no-ff我会使用git rebase master.但是,如果要在开发期间与同事共享功能分支,那么最好将主分支定期合并到功能分支中.
但说实话,我在一个小团队工作,如果我们需要共同完成一个功能分支,我们需要让它与主人保持同步,那么我们暂时暂停我们的工作(并清楚地传达这个过程) ,对master和force强制推送功能分支.但是,这对于更大的球队来说并不具备规模.但是,我发现使用在master上重新定义的功能分支更方便,而不必处理来自master的合并.
一定要读这个.