Skip to content

Instantly share code, notes, and snippets.

@RubenKelevra
Last active October 21, 2025 00:06
Show Gist options
  • Save RubenKelevra/5efe0cf240dc02226784d4fd64f8ec6a to your computer and use it in GitHub Desktop.
Save RubenKelevra/5efe0cf240dc02226784d4fd64f8ec6a to your computer and use it in GitHub Desktop.
Github only accepts pushes up to 2 GB as they are bundled into a single pack - this allows for a partial push via `git partial-push origin branchname` after placing it into .gitconfig. Error message"remote: fatal: pack exceeds maximum allowed size (2.00 GiB) error: remote unpack failed: index-pack abnormal exit"
[alias]
partial-push = "!sh -c
'REMOTE=$0;BRANCH=$1;BATCH_SIZE=100;
if git show-ref --quiet --verify refs/remotes/$REMOTE/$BRANCH; then
range=$REMOTE/$BRANCH..HEAD;
else
range=HEAD;
fi;
n=$(git log --first-parent --format=format:x $range | wc -l);
echo "Have to push $n packages in range of $range";
for i in $(seq $n -$BATCH_SIZE 1); do
h=$(git log --first-parent --reverse --format=format:%H --skip $i -n1);
echo "Pushing $h...";
git push $REMOTE ${h}:refs/heads/$BRANCH;
done;
git push $REMOTE HEAD:refs/heads/$BRANCH'
"
# Author: Crt Mori on stackoverflow.com
# Source: https://stackoverflow.com/a/72977369
@KZeni
Copy link

KZeni commented Oct 20, 2025

If anyone gets a fatal: bad config line # in file ~/.gitconfig or similar error, I had to update the code in this gist to be the following (I also added some additional comments):

[alias]
	partial-push = "!sh -c 'REMOTE=$0;BRANCH=$1;BATCH_SIZE=100; if git show-ref --quiet --verify refs/remotes/$REMOTE/$BRANCH; then range=$REMOTE/$BRANCH..HEAD; else range=HEAD; fi; n=$(git log --first-parent --oneline $range | wc -l); echo "Have to push $n packages in range of $range"; for i in $(seq $n -$BATCH_SIZE 1); do h=$(git log --first-parent --reverse --format=format:%H --skip $i -n1); echo "Pushing $h..."; git push $REMOTE ${h}:refs/heads/$BRANCH; done; git push $REMOTE HEAD:refs/heads/$BRANCH'"
# This allows for a partial push (aka push staged commits in batches rather than all in one package) via `git partial-push origin main` (or whatever the branch name is, if not "main") after placing this into ~/.gitconfig (or whever one's .gitconfig file is located.)
# Edit the BATCH_SIZE above (be it 500, 100, 10, or even 1) to best fit your needs.
# Author: Crt Mori on stackoverflow.com
# Source: https://stackoverflow.com/a/72977369/1275054
# Found via: https://gist.github.com/RubenKelevra/5efe0cf240dc02226784d4fd64f8ec6a

Essentially just needed to make the alias be on a single line (and is actually how the StackOverflow link in the comment actually initially provided it.) I also implemented the patch suggested in the comments in that StackOverflow answer (replace --format=format:x with --oneline) to avoid it miscounting commits and/or keep the output more condensed. 👍

That said... this just got rid of that upfront syntax error I encountered. It's in the process of running partial-push now so I'm waiting to find out if it successfully got around the remote: fatal: pack exceeds maximum allowed size (2.00 GiB) error (while it seems this actually doesn't fix things for a single commit being larger than 2GB so I'll just make smaller commits for my specific situation [while this will still be helpful to push those then-smaller commits in one go.])

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