On Friday, May 26, 2023 at 5:46:34 AM UTC-6 David Balazic wrote:
Hi! With the git plugin, is there a way to clone a repo with the --single-branch option? We have a freestyle job wit a Git source code, where we specify the branch as: refs/heads/main And when the build is done, the cloned repo (the .git folder) is very big, about 2.6 GB. We use a command line git implementation (gitforwindows.org 2.40.1). Using command line to clone gives this values: git clone --branch main https://server.example.com/foo/bar "C:\tmp\git test\test_xxx_branch_main" git clone --single-branch --branch main https://server.example.com/foo/bar "C:\tmp\git test\test_xxx_branch_main_single" The first creates a 2.6 GB .git folder, while the second a 70 MB sized .git folder. They both also have about 120 MB of working tree files. So about 2.4 GB is "wasted" due to unneeded cloned branches. Is there a way to make the Jenkins git plugin to clone only the required branches? Yes, you can match the behavior of the --single-branch argument to git clone with the Jenkins git plugin. Configure a refspec that matches a single branch in the remote configuration section. Enable "Honor refspec on initial clone" Those options are described in a git plugin Pipeline example <https://github.com/jenkinsci/git-plugin#checkout-with-a-narrow-refspec>. If you don't need the history of the repository in your job, you can reduce the size even further by using a shallow clone that only retrieves the most recent commit. That option is also described in a git plugin PIpeline example <https://github.com/jenkinsci/git-plugin#checkout-with-a-shallow-clone-to-reduce-data-traffic> . You can reduce disc use even further if you have a copy of the remote repository already available on the agent. Then you can use a reference repository. Reference repositories are generally not helpful when using shallow clone, since the reference repository may not include many of the changes in the shallow clone. A 10-15 minute video <https://youtu.be/jBGFjFc6Jf8?t=6434> discussing various performance improvement options is also available if you prefer video. Mark Waite -- You received this message because you are subscribed to the Google Groups "Jenkins Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/d9b55add-c0ae-4440-ae86-0354d5082fb9n%40googlegroups.com.
