How to Fix Jenkins Build Failures Caused by Large .git Repositories
When Jenkins builds stall at the git clone step due to an oversized .git directory, you can shrink the repository by running Git garbage collection, using tools like BFG Repo‑Cleaner, enabling Git LFS for large files, or configuring a shallow clone with depth 1 to fetch only the latest commit.
Introduction
When using Jenkins to deploy a project, the build often fails at the git clone step. After analysis, the cause is that Jenkins first downloads (or builds) the .git folder.
As the number of project submissions increases, especially when large files are included, the .git folder grows significantly.
.git is a hidden folder that stores all metadata and objects of a Git repository, including the object database, branch and tag information, configuration, logs, history, and hook scripts.
Now that the cause of slow or failing Jenkins builds is identified, how can it be resolved?
Solutions
Method 1: Compress the .git folder
You can use Git's built‑in commands to compress the .git directory. Run: git gc --aggressive --prune=all This invokes Git's garbage collection to clean and compress unused objects and remove unnecessary history, reducing the size of the .git folder.
Third‑party tools such as BFG Repo‑Cleaner can also clean and optimize the repository.
If the large size is due to big files, consider deleting those files or using Git's LFS (Large File Storage) extension to store large files externally, thereby shrinking the .git folder.
Method 2: Shallow clone (recommended)
If you do not need the full history and only care about the latest commit, use Git's shallow clone feature. Run:
git clone --depth 1 -b <branch> <repo_url>This clones only the most recent commit and files, without copying the entire history.
In Jenkins, configure this by opening the project's Git settings, adding an Advanced clone behaviours under Additional Behaviors , and setting Shallow clone with depth 1.
Reference: https://blog.csdn.net/qq_20042935/article/details/131422066
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
