Build server git mirror

418 Views Asked by At

Scenario

We have had (and still do have) a connectivity problem with Bitbucket where our download speed is very slow (and we have quite a large repo) and using Team City that from time-to-time likes to wipe the git repo that it downloaded, it can take up to 5 hours to pull the entire repo again. Not knowing how to switch off this repo wipe idea from Team city and not knowing how long this speed issue will persist, we decided to create a local mirror of bitbucket that Team City can connect to, to fetch the entire repo (which takes 5 minutes instead of 5 hours).

Solution

What I've done to accomplish this is to create a bare Git repository.

C:\My_bare_repo> git init --bare

Then I pushed my local development repository to this new bare repository by adding the bare repository as a new remote one (since I don't want to do a clone that will take 5 hours to complete).

After that I added my bitbucket url as a remote url on my bare repository.

C:\My_bare_repo> git remote add origin https://bitbucket.org/my_repo.git

Then I did a remote update.

C:\My_bare_repo> git remote update origin

I then wrote this PowerShell script that would be executed (via Windows Task Scheduler every 5 minutes):

git fetch --all --tags

git branch --list | % {
    git branch -D $_.Replace(" ", "")
}

git branch --remotes | where { ($_.Replace(" ", "")) -ne "origin/master" } | % {
    $remote = $_.Replace(" ", "")
    $local = $remote.Replace("origin/", "")

    git branch --track $local $remote
}

git push origin --tags

Outcome

It doesn't do a full sync (and I don't want it to sync with Bitbucket other than pushing any new tags that Team City created). It seems to be working as it successfully propagates the tags to Bitbucket and makes sure that the latest copy of the Bitbucket repo is on the bare repo for Team City to look at.

Questions

My question though is, are there any solutions like this already that would be better to use than what I've come up with?

Also, I don't like how I have to delete the branches and recreate them to ensure that they are on the same position in the repo where the origin branches are. Is there a way to fast-forward them (for a lack of a better term) on a bare repo?

0

There are 0 best solutions below