Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move remote branch tip from one branch to another

Tags:

git

rebase

commit

I did a rebase --onto to move a previous commit (c4) from master to a feature branch. But I had already pushed master to the remote origin.

So currently now I have

c1 - c2 - c3 - c5(master HEAD)
           \
            c4(feature HEAD) - c5(origin/master HEAD)

I realize that fixing this will screw up anyone who has pulled in changes from origin/master. But there is only one other developer so this is not that much of an issue. How do I change origin/master so it's not after the feature branch. I'd like it to be this:

c1 - c2 - c3 - c5(master HEAD)(origin/master HEAD)
           \
            c4(feature HEAD)
like image 992
Sean Lynch Avatar asked May 26 '15 17:05

Sean Lynch


People also ask

How do I move a remote from one branch to another?

In order to switch to a remote branch, make sure to fetch your remote branch with “git fetch” first. You can then switch to it by executing “git checkout” with the “-t” option and the name of the branch.

How do you move uncommitted changes from one branch to another?

Using the git checkout Command The git checkout -b <BranchName> command will create a new branch and switch to it. Moreover, this command will leave the current branch as it is and bring all uncommitted changes to the new branch.


1 Answers

Use a forced push from master to origin/master:

git push origin master:master --force

The other developer will need to reset his master to the remote master afterwards (preferably a hard reset after saving his work):

git fetch origin
git checkout master
git reset --hard origin/master
like image 90
TimWolla Avatar answered Oct 12 '22 13:10

TimWolla