1

I have a Bamboo CI system with multiple agents (i.e. distributed), each build gets assigned to the next available agent; Also note that multiple builds of different branches of the same repository might run concurrently on the same machine

My build needs to checkout the code from a remote git repository and that is as far as the integration with git goes.

Currently the build clones the repository prior to each build (hard requirement) and keeps the complete git repository (i.e. .git directory) for each of the branches on the same file system.

As the build does not interact with git in any way (e.g. push, pull) other than checking out the latest code I would like to simply, in lamens terms, download the latest version of a given git branch and nothing more.

Would appreciate any assistance

Guy Segev
  • 41
  • 5

4 Answers4

2

I'm by no means a git expert, but maybe this similar Stack Overflow question will help point you in the right direction:

Do a "git export" (like "svn export")?

Community
  • 1
  • 1
Jason Iwinski
  • 363
  • 3
  • 6
1

OK, this is how I would do it:

Setup:

git init build_dir
cd build_dir
# repeat for all repositories
git remote add REPO_NAME GIT_REPO_URI

Checkout a specific branch:

git fetch --all # fetch all updates
git fetch REPO_NAME # just fetch one repo
git checkout master
git reset --hard REPO_NAME/repository

Once in a while run:

git gc --aggressive
Šimon Tóth
  • 35,456
  • 20
  • 106
  • 151
  • Thanks for the swift response but I would like to have as less impact as possible on the file system and cpu by only retrieving the actual source code without creating any local repository – Guy Segev Mar 14 '12 at 14:55
  • thanks for that, but all I really want is the code without any git repository, something similar to svn export – Guy Segev Mar 15 '12 at 07:14
1

It turns out that Bamboo 3.4 roughly follows Let_Me_Be's advice out of the box when ticking the 'Shallow clone' option (which has much more cool features such as multi repository plans, checkout task and git submodules)

Guy Segev
  • 41
  • 5
  • As well as being exactly what's required here, shallow builds are also the default when you [configure a Git source repository](https://confluence.atlassian.com/display/BAMBOO/Git). – Joe Jun 09 '14 at 06:52
1
git clone -b branchname --depth 1 git@git.example.com:repository.git /path/to/your/repo

This will create a so called "shallow clone". It only contains the very latest commit of the named branch. Thus you will only pull the absolutely necessary bits.

To cite from the git clone man page:

--depth <depth>
    Create a shallow clone with a history truncated to the specified number
    of revisions. A shallow repository has a number of limitations (you cannot clone
    or fetch from it, nor push from nor into it), but is adequate if you are only
    interested in the recent history of a large project with a long history, and would
    want to send in fixes as patches.

Edit: AFAIK git can not "export" from a remote directory directly. But the approach above is roughly equivalent to an export from remote. If you then don't want the .git directory, just remove it. This is way easier than in the SVN world as you have exactly one, not one in every freaking directory.

Holger Just
  • 52,918
  • 14
  • 115
  • 123