Skip to content

Instantly share code, notes, and snippets.

@eddiecorrigall
Last active August 5, 2021 14:47
Show Gist options
  • Save eddiecorrigall/2ba695e0d83e780d6d6be6ab61cd65a0 to your computer and use it in GitHub Desktop.
Save eddiecorrigall/2ba695e0d83e780d6d6be6ab61cd65a0 to your computer and use it in GitHub Desktop.
Git Packfiles

I am sure some of you, like me, have cloned a repository and experienced the long wait time to copy data locally with a fast computer and fast internet. The repository might have large Git packfiles .git/objects/pack which surpass 1G in size. Digging a little deeper, you might find that this might be caused by blob files: assets in the repository. While not necessarily a bad thing, some of these files might be better off in another repository, since they do not appear necessary to run or deploy the app.

In the meanwhile, to save a little time, you can always shallow copy (0m49.415s on my computer):

# Shallow clone staging
git clone \
    --branch staging \
    --single-branch \
    --shallow-since='1 days' \
        [email protected]:<my-username>/<my-repo>.git

# List all file sizes in descending order from the current directoy
du \
    --human-readable \
    --max-depth=1 "$PWD" \
        | grep --extended-regexp 'K|M|G' \
        | sort --human-numeric-sort --reverse
3.1G  /Users/eddie/repos/code
2.1G  /Users/eddie/repos/code/.git
496M  /Users/eddie/repos/code/analytics
162M  /Users/eddie/repos/code/app
94M   /Users/eddie/repos/code/marketing
...
# List files with png extension, and include a total
find . -name "*.png" -print0 | xargs -0 du -sch
...
208M	total

Some files types to consider:

Extension Size
png 221M
jpg 96M
jl 54M
mp4 27M
gif 18M
pdf 13M
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment