Git hangs while writing objects [ Writing objects: 53% (22/41) ]

Git hanging – the Problem

Your git push is hanging at the Writing Objects

Writing objects:  53% (22/41)

If Git hangs while writing objects, it could be due to various reasons. Here are some common causes and possible solutions:

  1. Large Files: If you’re trying to commit or add huge files to the Git repository, the process can take a long time, and it may seem like Git is hanging. Consider excluding large binary files from version control using .gitignore or using Git’s Large File Storage (LFS) for managing large files.
  2. Insufficient Disk Space: Git needs enough free disk space to write objects during commits. If your disk is nearly full, Git might hang. Check your disk space usage and ensure you have enough space available.
  3. Slow Network: If you’re using a remote Git repository over a slow network connection, writing objects may take a long time. Make sure you have a stable and fast internet connection.
  4. Git Configurations: Some configurations in your Git settings can affect the performance. Check if you have any global or local Git configurations causing the slowdown.
  5. Anti-virus Software: Certain anti-virus software may interfere with Git’s operations, including writing objects. Consider adding Git and your repository directory to the list of exceptions in your anti-virus software.
  6. Corrupted Repository: In rare cases, a corrupted repository can cause Git to hang during object writing. You can try cloning the repository into a new directory to see if the issue persists.
  7. Git Version: Ensure you are using the latest version of Git. Older versions may have bugs or performance issues resolved in newer releases.

Git Hanging – Troubleshooting

To diagnose the issue further, you can try running Git commands with the GIT_TRACE environment variable set to 1, which will provide more detailed output:

GIT_TRACE=1 git <your_git_command>

You will get more verbose output like the below:

dev@codetryout:~/devops$ GIT_TRACE=1 git push
15:26:14.177982 git.c:439               trace: built-in: git push
15:26:14.178316 run-command.c:663       trace: run_command: unset GIT_PREFIX; ssh [email protected] 'git-receive-pack '\''codetryout/devops.git'\'''
15:26:18.237021 run-command.c:663       trace: run_command: git pack-objects --all-progress-implied --revs --stdout --thin --delta-base-offset --progress
15:26:18.239131 git.c:439               trace: built-in: git pack-objects --all-progress-implied --revs --stdout --thin --delta-base-offset --progress
Enumerating objects: 52, done.
Counting objects: 100% (52/52), done.
Delta compression using up to 2 threads
Compressing objects: 100% (40/40), done.
Writing objects:  53% (22/41)

Git Hanging – Solution

Referring to this StackOverflow solution – https://stackoverflow.com/questions/6887228/git-hangs-while-writing-objects

Increase the HTTP POST Buffer to a higher number.

git config --global http.postBuffer 524288000

If none of the above solutions works, consider seeking help by contacting your version control hosting provider (Your company git Administrator) for assistance. They might have additional insights into the specific issue you are facing.