Update a fork with new commits on its master branch?

I forked branch A and created B. Now, A has been updated by others and I'd like to bring those commits over to my B fork, so I can ensure the stuff I've been doing there still works with that new A content.

How can I do this? Git's terminology (pull, fetch, merge, etc.) is hugely unintuitive, at least early on :(


I would advise (if none has already pulled from B):

What you have is a Branch A with new evolution and possible commits done in the upstream repo :

        a--a--a (origin/A)
       /
a--a--a A
 
  b--b--b (B, local branch) 

First make sure A is up-to-date with the upstream repo content: origin/A :

git checkout A
git pull

That will give you:

a--a--a--a--a--a (A, origin/A)
 
  b--b--b (B, local branch) 

Then You would rebase your local modifications done on B on top of A (I suppose here that A has an upstream branch, meaning it does track origin/A , which you can check with git branch -avvv )

git checkout B
git rebase A

Which gives you:

a--a--a--a--a--a (A, origin/A)
                
                 b'--b'--b' (B, local branch) 

Note that changes the history of B , so if B was already pushed, you would have to push --force origin B , which can be dangerous if others already started working on B .
See (for more on the rebase tricks):

  • "Git push rejected after feature branch rebase"
  • " git rebase and git push : non-fast forward, why use?"

  • Note: "fork a branch" isn't the recommended expression, since fork is more commonly used to refer to a cloned repo on the server side: see "Git fork is git clone?".

    Instead, you would say: "I branched A and created B ": the operation is "branching" (not "forking").

    链接地址: http://www.djcxy.com/p/49254.html

    上一篇: 从存储库中删除本地更改

    下一篇: 在主分支上更新新的提交分支?