Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the origin of git branch

Tags:

git

git-remote

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

like image 473
user3546762 Avatar asked Sep 29 '15 07:09

user3546762


1 Answers

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
like image 98
Schwern Avatar answered Sep 30 '22 07:09

Schwern