I'm addicted to git stash && git stash drop as a quick way to bring my repo. to a clean state. I am curious to know what is your way of doing this?
TIL checkout takes a <path> as an argument which you can use to go back to the "clean" state of the given <path>.
So, you can use git checkout . to remove all uncommitted changes in all the files (This will not have any effect on untracked files, though!)
same as you said git checkout . will reset the head to the state that was once you `git pull origin $current_branch`
if you want to reset the branch to the state it was before pushing, like you committed multiple commits and you don't want to revert commit by commit, run this git reset --hard origin/$current_branch this will reset the head to the state that the origin has.
last thing if you want to remove the untracked files and folders use this : git clean -d -f _-d is for removing the directories, -f _to force it.
Developers use Git as they please from whatever I have seen and I am not quite sure what's the best way to remove your uncommitted local changes. Stashing works very well for me as well, but I have sometimes applied the wrong stash and got conflicts, which is when hard reset comes to the rescue. Hard reset only if you're ok with losing your local uncommitted changes, though.
git checkout . Unless I might want them then I stash.
Engineering an eGovernance Product | Hashnode Alumnus | I love pixel art
Pratik Upacharya
Your Problem Solver
Two scenarios
1) You care about the uncommited code
Lets say you are trying to add a new feature but you are lost and you want to start it from fresh, also don't want to lose whatever you have done till now. So that you can get that code anytime.
git stash list
(check if anything in the stash, if you want to clear the stash then then clear it using
git stash clear)
git stash ( to add uncommited code into stash)
Now you have a fresh new start, you can apply the code in stash anytime.
git stash apply <name of the stash>
2) You don't care about the uncommited code
git reset --hard HEAD
Everything in the stash will wipe out. And you can not recover it, if that what you want.