🚀 DevOps & SRE Certification Program 📅 Starting: 1st of Every Month 🤝 +91 8409492687 🔍 Contact@DevOpsSchool.com

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

Git error: “remote: fatal: pack exceeds maximum allowed size (2.00 GiB)”

Error

"remote: fatal: pack exceeds maximum allowed size (2.00 GiB)"

Solution

Step 1 – First add and Commit in Smaller chunk

To use this script, save it to a file with a .sh extension, make it executable using chmod +x <filename>.sh, and run it in the terminal, passing the commit message as an argument:
./git-add-commit.sh "Small fix"
#!/bin/bash
# Here's a shell script that adds and commits changes in a Git repository in smaller chunks:
# Usage: git-add-commit.sh <message>
# Check if a commit message was provided
if [ $# -eq 0 ]; then
echo "Error: No commit message provided"
exit 1
fi
# Store the commit message in a variable
message="$1"
# Add changes in smaller chunks
for file in $(git diff --name-only --cached); do
git add "$file"
git commit -m "$message"
done

Optional – add and Commit in Smaller chunk

To use this script, save it to a file with a .sh extension, make it executable using chmod +x <filename>.sh, and run it in the terminal, passing the commit message as an argument:
bash
Copy code
./git-add-commit.sh "Small fix"
# Here's a shell script that adds and commits changes in a Git repository in smaller chunks of 500 MB:
#!/bin/bash
# Usage: git-add-commit.sh <message>
# Check if a commit message was provided
if [ $# -eq 0 ]; then
echo "Error: No commit message provided"
exit 1
fi
# Store the commit message in a variable
message="$1"
# Function to determine the size of a file in MB
function size_in_mb() {
echo $(( $(wc -c < "$1") / 1048576 ))
}
# Store the sum of sizes of staged files in a variable
staged_size=$(git diff --cached --name-only | xargs du -c | tail -n 1 | awk '{print $1}')
# Add changes in smaller chunks
while [ "$staged_size" -gt 0 ]; do
chunk_size=0
for file in $(git diff --name-only --cached); do
file_size=$(size_in_mb "$file")
if [ "$((chunk_size + file_size))" -le 500 ]; then
chunk_size=$((chunk_size + file_size))
git add "$file"
fi
done
git commit -m "$message"
staged_size=$(git diff --cached --name-only | xargs du -c | tail -n 1 | awk '{print $1}')
done

Step 2 – shell script to push in chunk of 100 commits at a time

# Adjust the following variables as necessary
REMOTE=origin
BRANCH=$(git rev-parse --abbrev-ref HEAD)
BATCH_SIZE=100
# 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
done
# push the final partial batch
git push $REMOTE HEAD:refs/heads/$BRANCH
view raw push.sh hosted with ❤ by GitHub
Subscribe
Notify of
guest


0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments

Certification Courses

DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:

DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.

0
Would love your thoughts, please comment.x
()
x