与分支保持最新 [英] Keeping a branch up to date with master

查看:47
本文介绍了与分支保持最新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个远程存储库,该存储库已提取并从中进行分支.我想通过对master所做的更改来使新分支保持最新.我正在考虑下面的工作流程,这有意义还是有更好的方法来做到这一点?

I have a remote repository that I've pulled and am branching from. I want to keep the new branch up to date with changes done to master. I'm thinking about the workflow below, does it make sense or are there are better ways to do this?

  1. 初始分支和签出:

  1. Initial branching and checkout:

git checkout master

git pull

git checkout -b my_branch

  • my_branch中进行一些工作,然后定期进行:

  • Do some work in my_branch, then periodically:

    git checkout master
    
    git pull
    
    git checkout my_branch
    
    git merge master --no-ff
    

  • 根据需要重复执行步骤2,并定期按入远程my_branch.

    Repeat step 2 as needed, with periodic pushes to the remote 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更新您的远程分支,当您不打算在该分支上工作时,通常不需要分支的本地副本.

    git fetch updates your remote branches, there usually is no need to have a local copy of a branch when your are not planning to work on this branch.

    设置git config --global merge.ff false后,您可以省略--no-ff.

    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).
    

    请注意,git pull只是git fetchgit merge的组合.

    Be aware that git pull is just a combination of git fetch and git merge.

    通常,您只需要git pull --rebase(本质上是git fetchgit rebase),并创建更清晰的历史记录.

    Usually you just want git pull --rebase which is essentially git fetch plus git rebase, and creates a much cleaner history.

    您的定期推送"是否有任何原因?如果没有其他人在同一个分支上工作,那就太好了,只需要在完成所有操作后再进行推送即可.

    Is there any reason for your "periodic pushes"? If no one else is working on the same branch it would be perfectly fine, just to push after finishing everything.

    这篇关于与分支保持最新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆