5

Is it possible to clone only a single git branch in hudson ? Hudson version 2.2.0 with git plugin version 2.2.0 clones the entire specified project, thus occupying lot of space (which is expected to grow forever)

Thanks in advance.

crankparty
  • 1,230
  • 3
  • 17
  • 26

4 Answers4

5

Configuring refspec in the hudson-git plugin to the following value seems to be working:

+refs/heads/master:refs/remotes/origin/master

Addendum for 2023:

In 2023 that is not enough, the "Honor refspec on initial clone" option under "Advanced clone behaviours" must also be enabled.

Also "Shallow clone" can be enabled at the same place to save a bit more space (it omits downloading the history, it download only the latest version).

David Balažic
  • 1,319
  • 1
  • 23
  • 50
crankparty
  • 1,230
  • 3
  • 17
  • 26
  • Interesting to know. +1 (probably easier than my initial answer) – VonC Dec 10 '12 at 09:40
  • This does not seem to work for me. If I clone with command line and use the --single-branch option, I get a 200 MB local repo size, but in Jenkins I get 2.6 GB. I tried many options in Jenkins git plugin, but nothing helped thus far. I use Jenkins 2.387.2 with git plugin 5.0.2. I tried the above branch specifier, in "Advanced clone behaviours" I turned off "Fetch tags", enabled "Honor refspec on initial clone" and "Shallow clone", none helped. – David Balažic May 26 '23 at 10:34
  • See here for a working solution (I'll try to post a summary later): https://groups.google.com/g/jenkinsci-users/c/5eWKZfdu2Ls – David Balažic Jun 14 '23 at 11:33
2

Not directly, but if you can adapt the Hudson Git Plugin itself, you could clone only a branch with the right git command:
See "How to clone a single branch in git?"

This is possible since git1.7.10:

git clone <url> --branch <branch> --single-branch <folder>

Note that the git plugin 2.0 will allow to specify the right branch to clone:

git 2.0

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

You are confusing clone with checkout. Clone clones a repository, and that's how git works, checkout wil switch you to a given branch. Git is distributed thus, whole repository is copied with clone to your local machine. So you can access any branch, commit, tag, ever pushed.

damiankolasa
  • 1,508
  • 9
  • 8
  • Agreed that clone is different from checkout . But still , i meant to ask if we can do 'git archive' or someother git trick to reduce space consumption – crankparty Dec 07 '12 at 11:26
0

A git "branch" is just a 40-byte bookmark pointing to a position in the project history -- unless your branches are massively divergent, you aren't really saving much space, as you'll be downloading the full history anyway.

If space saving is the goal, perhaps use the "shallow clone" option? That'll only download one layer of history, rather than all of it.

Shish
  • 2,773
  • 19
  • 16