8

I have created branch this way:

git branch MyBranch origin/test

test was branch parallel to master. Now test is merged into master

How can i change the origin of MyBranch so it points to master

jub0bs
  • 60,866
  • 25
  • 183
  • 186
user3546762
  • 117
  • 1
  • 2
  • 6
  • 1
    You want to simply change the remote tracked branch or you want to `git rebase`? – Sergio Tulentsev Sep 29 '15 at 07:51
  • 2
    possible duplicate of [How do I change the remote a git branch is tracking?](http://stackoverflow.com/questions/4878249/how-do-i-change-the-remote-a-git-branch-is-tracking) – rubenvb Sep 29 '15 at 07:51

1 Answers1

13

There is no "origin" of a branch. A "branch" is just a label pointing at particular commit.

If you've made no commits to MyBranch, then you can delete and recreate it.

git branch -d MyBranch
git branch MyBranch master

If you have done work on MyBranch, then things are a little more complicated. Your situation is like this...

- A - B - C - D [master]
       \
        E - F [origin/test]
             \
              G - H [MyBranch]

MyBranch has commits G and H on top of origin/test. If you want to move MyBranch on top of master then you need to preserve the work in G and H. This can be done with a rebase.

git rebase --onto master origin/test MyBranch

This says to take the changes which are in MyBranch but not in origin/test (which is G and H) and put them on top of master. You get...

                G1 - H1 [MyBranch]
               /
- A - B - C - D [master]
       \
        E - F [origin/test]
             \
              G - H
Schwern
  • 153,029
  • 25
  • 195
  • 336