Short version
What is the easiest way to make a branch equal to master
again, discarding any differences?
Up until now, I simply used git branch -D wip
, followed by git checkout -b wip
, but that seems a bit silly.
Motivation
I often have a wip
branch alongside my master
branch, for 'work in progress'. Sometimes the work on such a branch gets 'left behind' and when I rediscover it, I find I no longer want it. This rediscovery often happens when I want to use the branch to store a new set of 'work in progress' and I find I simply want to discard any differences with master
, so the new 'work in progress' fits on top. Figuring out the differences is not worth the trouble: the solution described above works fine for me. Any better solutions to address this use case?
try this one in your branch :
git reset --hard master
This will make your branch identical to master, remove all commits you may have done, and discard all the files in the staging area.
If you really want to blow away the previous branch with that name, and create a new one you could just use:
git checkout -B wip master
Using the capital version rather than -b
will cause git to switch to the named branch, and reset it to the new starting point named as the last argument. If you're currently at the desired starting point you could leave off the last argument (master
here), it will default to using HEAD
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With