#!/bin/bash # This script pushes your repository in smaller chunks to avoid HTTP 413 errors # Set the remote and branch REMOTE="origin" BRANCH="main" # Get the list of commits in reverse order (oldest first) COMMITS=$(git rev-list --reverse HEAD) # Initialize variables LAST_PUSHED="" CHUNK_SIZE=10 TOTAL_COMMITS=$(echo "$COMMITS" | wc -l) CURRENT=0 echo "Total commits to push: $TOTAL_COMMITS" # Process commits in chunks for COMMIT in $COMMITS; do CURRENT=$((CURRENT + 1)) # If this is the first commit or we've reached the chunk size if [ -z "$LAST_PUSHED" ] || [ $((CURRENT % CHUNK_SIZE)) -eq 0 ] || [ $CURRENT -eq $TOTAL_COMMITS ]; then echo "Pushing commit $CURRENT of $TOTAL_COMMITS: $COMMIT" if [ -z "$LAST_PUSHED" ]; then # For the first commit, create a new branch at this commit and push it git checkout -b temp_branch $COMMIT git push -f $REMOTE temp_branch:$BRANCH LAST_PUSHED=$COMMIT git checkout $BRANCH git branch -D temp_branch else # For subsequent chunks, push the range from last pushed to current git checkout -b temp_branch $COMMIT git push -f $REMOTE temp_branch:$BRANCH LAST_PUSHED=$COMMIT git checkout $BRANCH git branch -D temp_branch fi # Check if the push was successful if [ $? -ne 0 ]; then echo "Error pushing commit $COMMIT. Exiting." exit 1 fi echo "Successfully pushed up to commit $CURRENT of $TOTAL_COMMITS" sleep 2 # Give the server a short break fi done echo "All commits pushed successfully!" git push -f $REMOTE $BRANCH # Return to the original branch git checkout $BRANCH echo "Done! Your repository should now be fully pushed to $REMOTE/$BRANCH"