Last active
April 28, 2025 21:33
-
-
Save ntanis-dev/1a64c535757992515c1f9effc2d1bbf7 to your computer and use it in GitHub Desktop.
Checks and displays the size of Git staged files. Tested in Ubuntu 22.04 LTS.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
num_files=$(git --no-pager diff --cached --name-only | wc -l) | |
if [ "$num_files" -eq 0 ]; then | |
echo -e "\033[91mERROR: You have no staged files.\033[0m" | |
exit 0 | |
fi | |
total_size=$(git --no-pager diff --cached --name-only -z | xargs -0 du -b | awk '{total += $1} END {print total / 1024 / 1024}') | |
total_size_int=$(echo $total_size | cut -d. -f1) | |
echo -e "\033[36m${num_files} staged file(s)\033[0m | \033[33m≈$(printf "%.2f" $total_size) MB total size\033[0m" | |
if [ $total_size_int -gt 1900 ]; then | |
echo -e "\033[91mWARNING: The total size of staged files is close to or greater than the GitHub push limit of 2GB.\033[0m" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Terminal one-liner in your repo's directory:
curl -s https://gist.githubusercontent.com/ntanis-dev/1a64c535757992515c1f9effc2d1bbf7/raw/git_staged_files_size_check.sh | bash