1 min read



Sometimes you want/need to reset the git folder to complete new code. Rather than simply removing the folder and repository and creating new one, the following method solves the problem in couple of minutes. Follow the instructions, of course, at your own risk! I can simply assure you that I used it and it worked in my case.

So here it goes

If you aren’t in the same folder as your older code or you don’t have your code at all, then get it first!

git pull origin master

To be sure that your are in master, git checkout to master. Then name the branch for the code, which you won’t need anymore (in this case, it is called old_stuff). Though it is not that necessary, it is recommended. In the end, push this branch to origin.

git checkout master
git branch old_stuff
git push origin old_stuff

Now change to a new branch that you want to use (called new_stuff here)

git checkout -b new_stuff

Now you are ready to remove all the old files you don’t need anymore

ls | xargs rm -rf

Copy new files, which you are going to use, in the same folder


Add all the new copied files to git

git add -A

Commit and push your new branch to origin

git commit
git push origin new_stuff

Now update master for newer branch

git push . HEAD:master

Finally, push the newer version of master to origin

git push origin master

That’s all. You had just reset your git, while still having your older code as old_stuff branch on remote origin. You can remove that branch anytime you want or keep it for future reviews.

Disclaimer: I am not responsible, if it creates any harm to your code or project. I would recommend you to understand each step, before you apply it. Best Luck!!!