Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

Install git filter-repo using a supported package manager or from source.

Clone a fresh copy of the repository using --bare and --mirror:

git clone --bare --mirror https://gitlab.example.com/my/project.git

Using git filter-repo, purge any files from the history of your repository.

To purge large files, the --strip-blobs-bigger-than option can be used:

git filter-repo --strip-blobs-bigger-than 10M

To purge large files stored using Git LFS, the --blob--callback option can be used. The example below, uses the callback to read the file size from the Git LFS pointer, and removes files larger than 10MB.

git filter-repo --blob-callback ' if blob.data.startswith(b"version https://git-lfs.github.com/spec/v1"): size_in_bytes = int.from_bytes(blob.data[124:], byteorder="big") if size_in_bytes > 10*1000: blob.skip() '

To purge specific large files by path, the --path and --invert-paths options can be combined:

git filter-repo --path path/to/big/file.m4v --invert-paths

See the git filter-repo documentation for more examples and the complete documentation.

Force push your changes to overwrite all branches on GitLab:

git push origin --force 'refs/heads/*'

Protected branches will cause this to fail. To proceed, you must remove branch protection, push, and then re-enable protected branches.

To remove large files from tagged releases, force push your changes to all tags on GitLab:

git push origin --force 'refs/tags/*'

Protected tags will cause this to fail. To proceed, you must remove tag protection, push, and then re-enable protected tags.

To prevent dead links to commits that no longer exist, push the refs/replace created by git filter-repo.

git push origin --force 'refs/replace/*'

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