Merge, update, and pull Git branches without using checkouts

前端 未结 17 1713
臣服心动
臣服心动 2020-11-22 07:42

I work on a project that has 2 branches, A and B. I typically work on branch A, and merge stuff from branch B. For the merging, I would typically do:

git mer         


        
17条回答
  •  不要未来只要你来
    2020-11-22 08:26

    In your case you can use

    git fetch origin branchB:branchB
    

    which does what you want (assuming the merge is fast-forward). If the branch can't be updated because it requires a non-fast-forward merge, then this fails safely with a message.

    This form of fetch has some more useful options too:

    git fetch  :
    

    Note that can be a local repository, and can be a tracking branch. So you can update a local branch, even if it's not checked out, without accessing the network.

    Currently, my upstream server access is via a slow VPN, so I periodically connect, git fetch to update all remotes, and then disconnect. Then if, say, the remote master has changed, I can do

    git fetch . remotes/origin/master:master
    

    to safely bring my local master up to date, even if I currently have some other branch checked out. No network access required.

提交回复
热议问题