Search code examples
gitgithubgit-rebasegit-remotegit-reset

Resetting a remote branch without pushing the local branch


I have the following situation in my project:

screenshot

I would like to get rid of the merge commit (c6ac755) and rebase master on b35dac5 instead. To this end, I would like to reset origin/master to b35dac5, rebase master on origin/master and then synchronize with GitHub. How can I reset origin/master without changing master and pushing it to origin?


Solution

  • It looks like you merged origin/master locally (probably with git pull), pushed the merge and then reset the local master branch with something like git reset --hard HEAD~1.


    In this state, you can use push to set the remote branch to the desired commit:

    git push --force origin b35dac5:master
    

    After this, you can rebase master on origin/master:

    git checkout master
    git rebase origin/master