Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git-svn - Checkout a remote branch that already exists in svn when my master is already a branch. Explain this .git/config

This is a bit of an oddball question given how the team I've joined is using SVN. Basically, the svn repository follows a standard layout, but trunk really hasn't been touched in 1.5 years or so and work tends to happen in branches and branches of branches only. As such, I've used git-svn to clone from the branch that represents the active branch for our next release and that is what master tracks in my local git repository. Let's call this branch in svn 'release' from here on out. Using git-svn for this purpose is just hunky dory.

Now, someone has created a feature branch off of 'release', that I'm going to call 'feature', that I'd like to pull down to a local branch of mine, and commit to as well. Sure, I can get away with just cloning that branch off into another directory/git repository locally, but what I'd really like to do is have 'feature' mirrored in a local branch within my local git repository as well to make merging between the two as straightfoward as possible. I've seen other stackoverflow.com posts show how this works assuming you've used git svn init with --stdlayout, but I didn't do that in my case for the reasons stated above.

Here is my .git/config

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[svn-remote "svn"]
    url = https://our.svn.server/svn/root/branches/release
    fetch = :refs/remotes/git-svn

I'm assuming what I need in my [svn-remote] section is a branches = $something but I don't know what that $something is in this case nor what incantation of git checkout and other commands I need after I make that change to .git/config.

Any suggestions?


Edit - The following works:

So I started from scratch and did the following clone command:

git svn clone https://my.svn.server/svn/root -T branches/branch_I_want_as_master -b branches

Which, after about 16 hours, finally pulled everything down that it needed to. The resultant .git/config looks like this:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[svn-remote "svn"]
    url = https://my.svn.server/svn/root
    fetch = branches/branch_I_want_as_master:refs/remotes/trunk
    branches = branches/*:refs/remotes/*

So I know this works - I can git checkout -b name-of-a-branch name-of-a-branch and it gives me the remote branch in my local git repo. The previous answers weren't the exact answers I needed, but I've upvoted since they were helpful.

At this point, I'll accept answer that just explains why this works and perhaps a useful link that breaks down how to do things properly with .git/config.

like image 379
whaley Avatar asked Feb 15 '11 13:02

whaley


2 Answers

You repository config should be looking like this:

[svn-remote "svn"]
url = https://our.svn.server/svn/root
fetch = branches/release:refs/remotes/git-svn
branches = branches/release/feature1:refs/remotes/branches/*
branches = branches/release/feature2:refs/remotes/branches/*

url should point at root of your repository. fetch points to your trunk (it could be any branch in fact), and there could be any number of branches entries, that points to your feature branches.

Maybe you should construct your git repository from scatch, but this config works.

like image 119
gor Avatar answered Sep 22 '22 16:09

gor


Have you tried just adding branches=.. to your svn-remote section? (presuming url points directly at your release branch). You'll get an extra release head tracking the release branch, but then you'll get all the other branches tracked too so that you can check them out. As a bonus git svn branch will (probably) work for creating new branches too!

As a side note, you could have also just used --stdlayout to clone your svn repo, and then set master up to track release instead of trunk. That's not hard to do either.

like image 25
Walter Mundt Avatar answered Sep 21 '22 16:09

Walter Mundt