user3546762
user3546762

Reputation: 127

Change the origin of git branch

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

Upvotes: 9

Views: 17614

Answers (1)

Schwern
Schwern

Reputation: 164809

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

Upvotes: 13

Related Questions