Useful Commands

Git

See how much space you’re using git gc
Quickly see how much space you’re using: git count-objects -v
Find the biggest objects/blobs in your database: git verify-pack -v .git/objects/pack/pack-<hash>.idx | sort -k 3 -n | tail -3
This chain of commands will identify the big objects and sort on the third field in the output, which is file size; then pipe it through the tail to get the last 3, for example: git verify-pack -v .git/objects/pack/pack-747fcb154b4b8f254f203cf383e7157ef6541ee6.idx | sort -k 3 -n | tail -3
output:
e3f094f522629ae358806b17daf78246c27c007b blob 1486 734 4667
05408d195263d853f09dca71d55116663690c27c blob 12908 3478 1189
7a9eb2fba2b1811321254ac360970fc169ba2330 blob 2056716 2056872 5401
You can use this to find your blob’s name git rev-list --objects --all | grep 7a9eb2fb See all commits that modified a file. git log --pretty=oneline --branches -- pathToFile To remove a file from the specified SHA1 hash, all the way downstream. git filter-branch --index-filter 'git rm --cached --ignore-unmatch <path-to-file>' -- <sha1-where-the-file-was-first-added>..
Here is an example, see here for explanation: Git-Internals-Maintenance-and-Data-Recovery git filter-branch --index-filter 'git rm --cached --ignore-unmatch composer.phar' -- 458be400a569db6f115539c2d70e616f6d2a0ace..
output:
Rewrite 458be400a569db6f115539c2d70e616f6d2a0ace (1/63)rm 'composer.phar'
Rewrite 213c17252af95c81f14333f983bf974447b465c0 (2/63)rm 'composer.phar'
Rewrite 596998f39e23e1bda7eeadcfeb5fb4bb967bd89d (3/63)rm 'composer.phar'
...
Remove any refs to a removed file, then repack the database. rm -Rf .git/refs/original
rm -Rf .git/logs/
git gc
Clone a single branch. git clone <url> --branch <branchName> --single-branch [folder] Prepare a sub-directory in a project to be split off as its own new project: git subtree split -P <sub-directory-to-split-off> -b <new-split-branch-1> Now create a new directory and initialize it: mkdir <newRepo> && cd <newRepo> && git init Now we officially make the new repo by pulling in the split off branch: git pull <path-to-repo-with-new-split-branch-1> <new-split-branch-1> You may want to bring the unit test along as well. Just split them off to a new branch like before: git subtree split -P <sub-directory-to-split-off-test> -b <new-split-branch-1-test> Add a single branch of another repository under a sub-directory, while retaining its history: git subtree add --prefix=<dest-directory> <path-to-repo-with-new-split-branch-1-test> <new-split-branch-1-test>