Skip to content

Instantly share code, notes, and snippets.

@sohang3112
Created December 4, 2025 19:16
Show Gist options
  • Select an option

  • Save sohang3112/550abcaa68af63298f3b69c4228c1e0e to your computer and use it in GitHub Desktop.

Select an option

Save sohang3112/550abcaa68af63298f3b69c4228c1e0e to your computer and use it in GitHub Desktop.
Shrink .git folder size by converting merge commits into normal squash commits
# 'Squash Merge' video by anthonywritescode, this is script shown at timestamp 16:50 :
# https://youtu.be/5_8FTivl8Vs?si=krcdLDevrAC_DLuo&t=1013
# Uses https://github.com/newren/git-filter-repo (python script)
# Explanation: `git cat-file commit COMMIT_ID` shows parent commit id
# normal commits have 1 parent, merge commits have 2 parents
# this script simply deletes 1 parent (keeping only parent id of main branch),
# converting merge commit into normal (squash) commit
# An impressive example of this script is shown,
# where after running this script, .git/ folder shrank from gigabytes to megabytes !
git filter-repo --commit-callback '
if commit.message.startswith(b"Merge pull request"):
return commit
else:
assert len(commit.parents) == 2, vars(commit)
del commit.parents[1]
return commit
'
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment