1

Using Git, I was working on a feature branch. I pushed the branch to github so someone could look at it. Then, it had been a while, so I rebased it. How do I push my rebased branch over the old one? What pitfalls must I avoid? I think it's just git push --force (or --mirror?), but I'm never sure.

Some relevant links:

Community
  • 1
  • 1
Scott Stafford
  • 43,764
  • 28
  • 129
  • 177

1 Answers1

6

You want to use git push --force but please remember that you are rewriting public history.

Rewriting public history is a very bad idea. Anyone else who may have pulled the old history will have to git pull --rebase and even worse things if they have tagged or branched from the rewritten history, so you must publish your humiliation so they know what to do.

The server may not allow this (but will on github). See receive.denyNonFastForwards (git-config)

Seth Robertson
  • 30,608
  • 7
  • 64
  • 57
  • Assuming the (very small set of) other devs that have pulled the branch knew not to do anything with it other than pull it and look at it, what would they have to do? Simply run "git pull --rebase" and all will be well? – Scott Stafford Jul 18 '12 at 00:54
  • @Scott: If they looked at it as origin/foo, then they have to do nothing. If they created a local tracking branch foo, then they `git pull --rebase` If they created a local non-tracking branch, then they makt it tracking a `git pull --rebase`. Or, you know, delete the branch and recreate. – Seth Robertson Jul 18 '12 at 01:34