I currently have a local Git repository, which I push to a Github repository.
The local repository has ~10 commits, and the Github repository is a synchronised duplicate of this.
What I'd like to do is remove ALL the version history from the local Git repository, so the current contents of the repository appear as the only commit (and therefore older versions of files within the repository are not stored).
I'd then like to push these changes to Github.
I have investigated Git rebase, but this appears to be more suited to removing specific versions. Another potential solution is to delete the local repo, and create a new one - though this would probably create a lot of work!
ETA: There are specific directories / files that are untracked - if possible I would like to maintain the untracking of these files.
The other option, which could turn out to be a lot of work if you have a lot of commits, is an interactive rebase (assuming your git version is >=1.7.12):
git rebase --root -i
When presented with a list of commits in your editor:
Save and close. Git will start rebasing.
At the end you would have a new root commit that is a combination of all the ones that came after it.
The advantage is that you don't have to delete your repository and if you have second thoughts you always have a fallback.
If you really do want to nuke your history, reset master to this commit and delete all other branches.
Here's the brute-force approach. It also removes the configuration of the repository.
Note: This does NOT work if the repository has submodules! If you are using submodules, you should use e.g. interactive rebase
Step 1: remove all history (Make sure you have backup, this cannot be reverted)
Step 2: reconstruct the Git repo with only the current content
Step 3: push to GitHub.
The method below is exactly reproducible, so there's no need to run clone again if both sides were consistent, just run the script on the other side too.
If you then want to clean it up, try this script:
http://sam.nipl.net/b/git-gc-all-ferocious
I wrote a script which "kills history" for each branch in the repository:
http://sam.nipl.net/b/git-kill-history
see also: http://sam.nipl.net/b/confirm
The only solution that works for me (and keeps submodules working) is
Deleting
.git/
always causes huge issues when I have submodules. Usinggit rebase --root
would somehow cause conflicts for me (and take long since I had a lot of history).More info here.
Git tutoturial here provides help on how to purge repository:
I solved a similar issue by just deleting the
.git
folder from my project and reintegrating with version control through IntelliJ. Note: The.git
folder is hidden. You can view it in the terminal withls -a
, and then remove it usingrm -rf .git
.