9

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)
isherwood
  • 58,414
  • 16
  • 114
  • 157
Sean Lynch
  • 2,852
  • 4
  • 32
  • 46
  • Does your configuration allow you to delete `origin/master`? It could be that simple. – isherwood May 26 '15 at 17:23
  • I have full access to the remote and it's my repo. So I can do whatever is necessary. But if there's a solution that doesn't require deleting `origin/master` that would probably be the best answer to the question. – Sean Lynch May 26 '15 at 17:28
  • So if I was going to delete `origin/master`, I would just delete that remote, add it as the tracking branch for `master`, and then do a `git -f push`. Is that correct? – Sean Lynch May 26 '15 at 17:30
  • Maybe just `git push origin :master`, and then `git push`. Shouldn't need to force it. – isherwood May 26 '15 at 17:56

1 Answers1

16

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
TimWolla
  • 31,849
  • 8
  • 63
  • 96