Search code examples
gitrebasegit-remote

Git: Get changes from master to a remote branch


I am working on a project and we have development branches. Lets say we have branches: master, A, B

Let's say that history looks like this right now:

   7  
   |   
   6  merge commit
   |/ |
   4  |
   |  |
   3  |
   |  |
   a  5   b
    \ | /
      2 
      |
      1
      |
      m

where m, a and b are the branches and numbers are just commits. So I did some work on master, then created branch a, then did some work on a AND some work on master and then some work on a and then merged.

**Question is: ** What is the right way to get the commit 5 into branch a?

If it was a local branch I could just

git checkout a
git rebase master

But a is a remote branch and I know it is not safe to mess with remote history like that. What is the correct way of getting changes from master?


Solution

    1. create a local branch a tracking remote/a
    2. git checkout a
    3. git merge master
    4. git push

    You already merged one way; was there a specific reason you reached straight for rebase instead of merge in the other direction?

    Is it because you previously used some other VCS with broken merges? If so I can reassure you that git is perfectly capable of finding the common ancestor and performing a sane merge here.