Skip to content

Instantly share code, notes, and snippets.

@altfatterz
Last active January 24, 2024 09:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save altfatterz/cfea122b43d0157c888a1e2b3cad4cad to your computer and use it in GitHub Desktop.
Save altfatterz/cfea122b43d0157c888a1e2b3cad4cad to your computer and use it in GitHub Desktop.
push_commits_by_chunks
#!/bin/sh
REMOTE=mb
BRANCH=$(git rev-parse --abbrev-ref HEAD)
BATCH_SIZE=10
# count the number of commits to push
n=$(git rev-list --count HEAD)
echo "Commits to push: $n"
# push each batch
for i in $(seq $n -$BATCH_SIZE 1); do
# get the hash of the commit to push
h=$(git log --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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment