Make the current commit the initial commit in a Git repository
Published on 2017-12-10. Modified on 2018-11-12.
In this tutorial we're gonna take a look at how you can make the current commit in your Git repository the initial and only commit. This is useful if you're using Git as a backup solution and you want to clean out old files. It also works on GitHub.
This is the brute-force approach.
Note: This does NOT work if the repository has submodules! If you are using submodules, you should use e.g. interactive rebase.
Start by moving your config:
$ mv .git/config .
Then delete the Git repository:
$ rm -rf .git
Then reconstruct the Git repository with only the current content:
$ git init $ mv config .git/ $ git add . $ git commit -a -m "Initial commit"
Then push it:
$ git push -u --force origin master
If you have any comments or corrections please feel free to email them to me. Also, if you found this content useful consider supporting me on Patreon