Skip to content

Instantly share code, notes, and snippets.

@JuliaSprenger
Last active November 4, 2021 11:26
Show Gist options
  • Save JuliaSprenger/05810e0f7fe04062a32b3951c6520904 to your computer and use it in GitHub Desktop.
Save JuliaSprenger/05810e0f7fe04062a32b3951c6520904 to your computer and use it in GitHub Desktop.
Remove git-annex history locally and remotely

How to remove the history from a git-annex repository.

Here we are reducing the commit log of git and git-annex branches to a single commit. The following lines assume the repository has only a single remote 'origin', on which the history of the commits will also be reduced to a single commit. Note: Don't change the history of publicly shared repositories as this will lead to in inconsistent histories between different local copies of the repository.

Resetting local branches to a single commit

Squashing the master branch git reset $(git commit-tree HEAD^{tree} -m "<Your single commit message>")

Squashing git-annex branch git annex forget --drop-dead --force

Force pushing modified branches

git push -f origin master
git checkout git-annex
git push -f origin git-annex

... and switching back to the master branch git checkout master

Removing inconsistent synched branches

Deleting synced/... branches locally

git branch -D synced/master
git branch -D synced/git-annex

Deleting synced/... branches remotely

git push -d origin synced/master
git push -d origin synced/git-annex

Verify the result

Now git should only be aware of 4 branches in total (2 local and 2 remote) git branch -a should print

git-annex
* master
remotes/origin/git-annex
remotes/origin/master

The removed synced/... branches should be automatically recreated when continuing to work with the repository.

@morales-gregorio
Copy link

morales-gregorio commented Nov 4, 2021

Yes, I made it rather for myself ;) I can delete the comment after we have DOI in our repository

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment