Clean your git branch from changes
Sometimes we are changed a lot in our newly created git branch or an existing one, and we need to clear all things at once due to any reason.
So we need to clean our branch from the initial time, a basic command we are used for clean namely git stash but it only removes all of the content of the changed files to the original content.
But what about our newly created files and directory, git stash still not removed these files.
Get Saiful Alam Rakib’s stories in your inbox
Join Medium for free to get updates from this writer.
So what can we do now, cause there were a lot of files I created, can I delete these files one by one.
Nope!, here is a pretty solution contain in git. let’s start to clean our git branch.
First of all, see your all untracked files by running this command git status after that you will see the untracked files list, then run another command here
git clean -n
you will see, all of the files lists that will be deleted, use an extra parameter to see the directory lists also, so your final command will be,
git clean -nd
so we check our files and directories to be deleted or clean.
Now let’s do the final thing, run the command bellow to clean your git branch.
git stash — To clean the changes files.git clean -fd — To clean up your untracked files and folder.git clean -fX — To clear the ignored files also. (Optional)
Yeep, We are done.
Thanks for reading!









