If you've made the mistake of already committing something to your local main branch, you can fix things by doing something like:
git checkout -b myFeatureBranch
git stash
git checkout main
git reset --hard origin/main
git checkout myFeatureBranch
git stash pop
and now the myFeatureBranch branch will be exactly how your own main was before, while making your main totally clean.
There's probably a simpler one-liner to do all those things at once but I like using the separated steps that make it obvious exactly what's happening.
Exactly, it's just too much compared to always check out a new branch without even thinking about it. And according to my experience, most of those who work on master - in not a one-person project - they are not really familiar with stashing or even differences between hard and soft reset.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
If you've made the mistake of already committing something to your local main branch, you can fix things by doing something like:
and now the
myFeatureBranch
branch will be exactly how your ownmain
was before, while making yourmain
totally clean.There's probably a simpler one-liner to do all those things at once but I like using the separated steps that make it obvious exactly what's happening.
Thanks for your comment!
Exactly, it's just too much compared to always check out a new branch without even thinking about it. And according to my experience, most of those who work on master - in not a one-person project - they are not really familiar with stashing or even differences between hard and soft reset.