I was accidentally working on a branch I shouldn\'t have been for a while, so I branched off of it giving it the appropriate name. Now I want to overwrite the branch I shou
Assuming this is what happened:
# on branch master
vi buggy.py # you edit file
git add buggy.py # stage file
git commit -m "Fix the bug" # commit
vi tests.py # edit another file but do not commit yet
Then you realise you make changes on the wrong branch.
git checkout -b mybranch # you create the correct branch and switch to it
But master
still points to your commit. You want it to point where it pointed before.
The easiest way is:
git branch --force master origin/master
Another way is:
git checkout master
git reset --soft origin/master
git checkout mybranch
Note that using reset --hard
will cause your uncommitted changes to be lost (tests.py
in my example).