Search code examples
gitrebase

git rebasing a very old branch


My project uses a branch (say FEATURE) which was branched off master sine a long time (about 1 year).

On this branch there has been 100's of commits .... same thing on master as well. The 2 path have diverged quite a lot, and I would like to rebase the FEATURE branch on master, to reduce the differences. The rebase itself was lengthy, but can be solved. I did the rebase in a separate branch. Once the branch will be building correctly and thoroughly tested, my goal is to overwrite the FEATURE branch with it. This is a bit scary ....

Shall I simply do a git push --force --set-upstream origin/FEATURE ?

Thanks, Jacques


Solution

  • If you just want to push your rebased FEATURE branch to the remote, then use:

    git push --force origin FEATURE
    

    If you instead want to overwrite the FEATURE branch with some other rebased branch, called FEATURE_OTHER, then use:

    git checkout FEATURE
    git reset --hard FEATURE_OTHER
    git push --force origin FEATURE