Skip to content

Instantly share code, notes, and snippets.

@ambrose40
Created February 28, 2024 13:35
Show Gist options
  • Select an option

  • Save ambrose40/33c86859b55df7a32bdfa74edf6a1e2b to your computer and use it in GitHub Desktop.

Select an option

Save ambrose40/33c86859b55df7a32bdfa74edf6a1e2b to your computer and use it in GitHub Desktop.
Batch push commits - partial push
[alias]
partial-push = "!sh -c 'REMOTE=$0;BRANCH=$1;BATCH_SIZE=2; 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'"
@ambrose40
Copy link
Author

ambrose40 commented Feb 28, 2024

usage from console:
git partial-push origin main

@ambrose40
Copy link
Author

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