Certified studio & training center
ENFR
Lab

Reset git repository to a new commit

Git is an awesome version control system, popularized by Github. Working on a big project, you might need to add (huge) binaries, or libraries, or even psds, videos... to your repository. We'll…

Git is an awesome version control system, popularized by Github. Working on a big project, you might need to add (huge) binaries, or libraries, or even psds, videos… to your repository. We’ll not judge this method, it has its pros & cons. The fact is: if those big files change often, your repository will increase very quickly. And sometimes your own code versioning is not a big deal. It’s stable, and for newcomer it doesn’t need all the git history and its 4Go (yeah, I already experienced that). So let see how to reset your git repository to a new commit:

Firsty, save your local .git/config file somewhere on your disk. Then:

rm -rf .git
git init

Import and overwrite your previous .git/config file. Then:

git add .
git commit -m "Repository reset"
git push -f origin master

Et voilà!

A cool thing to notice is on Github and Bitbucket, you won’t lost data subscriptions, stars & forks.

Maybe you need a backup on a specific URL just in case…? Just create a new repository, and in your .git/config file change the url and push ;)

AL
Aymeric Lamboley
Founder & CTO
// STAY IN TOUCH

Studio news,
straight to your inbox.

One email a month at most: our technical articles, project debriefs and new training sessions. No spam, one-click unsubscribe.