Skip to content

Instantly share code, notes, and snippets.

@SomajitDey
Last active September 26, 2021 16:10
Show Gist options
  • Save SomajitDey/3a82013adbf4081f310f9df89df83e04 to your computer and use it in GitHub Desktop.
Save SomajitDey/3a82013adbf4081f310f9df89df83e04 to your computer and use it in GitHub Desktop.
Remove old commits and unnecessary objects form local (non-archive) repo to save on disk-space without affecting future updates: push/pulls

Remove old commits from local repo

Shallow fetch from self:

Keep only last n commits--

git fetch --depth=<n-1> . <branch>

Remove commits older than specified time--

git fetch --shallow-since="<timestamp>" . <branch>

Remove commits reachable from tag, including itself--

git fetch --shallow-exclude=<tag(but not commit hash)> . <branch>

(Optional) Remove unreachable objects to clean up disk-space following above removal of commits

git gc --prune=now	# Don't use --prune=now if another process is writing to the repository concurrently

Compare repo size before and after repo cleanup:

git count-objects -vH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment