Skip to content

Instantly share code, notes, and snippets.

@spenserhale
Last active March 5, 2024 19:21
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save spenserhale/19a2abd03c0558449202a1d7bcc64ed7 to your computer and use it in GitHub Desktop.
Save spenserhale/19a2abd03c0558449202a1d7bcc64ed7 to your computer and use it in GitHub Desktop.
When your repo exceeds upload limit (GitHub 2GB), you can push in batches so you can store up to total size limit. (100GB) (Warning uses force push, ideally should be used for setting up new remote, once)
# Adjust the following variables as necessary
REMOTE=origin
BRANCH=$(git rev-parse --abbrev-ref HEAD)
BATCH_SIZE=250
# check if the branch exists on the remote
if git show-ref --quiet --verify refs/remotes/$REMOTE/$BRANCH; then
# if so, only push the commits that are not on the remote already
range=$REMOTE/$BRANCH..HEAD
else
# else push all the commits
range=HEAD
fi
# count the number of commits to push
n=$(git log --first-parent --format=format:x $range | wc -l)
# push each batch
for i in $(seq $n -$BATCH_SIZE 1); do
# get the hash of the commit to push
h=$(git log --first-parent --reverse --format=format:%H --skip $i -n1)
echo "Pushing $h..."
git push $REMOTE ${h}:refs/heads/$BRANCH --force
done
# push the final partial batch
git push $REMOTE HEAD:refs/heads/$BRANCH --force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment