Search code examples
gitgit-push

Rebasing master without being able to push --force


I have my branch, say foo, that is also on origin. I'm the only one coding to this branch. Meanwhile, master changed and I need to pull those changes and then make some more changes onto my branch and push it. So I go ahead and:

git checkout foo
get rebase master
git commit ...
git push origin foo

Except this fails because it's not a fast-forward. I would normally do --force but we don't allow it here. If I pull origin/foo then I either get a bunch of conflicts that had to do with the master changes or my new changes in foo.

What is the correct workflow for a solo branch without --force?


Solution

  • You can do merge master to your foo instead of rebase it on master.

    1. git checkout foo
    2. git pull origin foo
    3. git merge master

    Solve conflicts, commit some changes and so on... And then you can push back to origin without --force

    1. git push origin foo

    After your finish with your branch and if you want to merge to stable branch you have to merge your foo branch to master:

    1. git checkout master
    2. git merge foo
    3. git push origin master

    foo: 0-----0--------(step2)---(step3)------0----0
                                  /                   \
    master: 0-------0------------0---------------------(step6)