DEV Community

loading...

Discussion on: The most important git practice

Collapse
fluffy profile image
fluffy • Edited

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
Enter fullscreen mode Exit fullscreen mode

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.

Collapse
sandordargo profile image
Sandor Dargo Author

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.