The standard repo layout in svn is as follows.
/trunk
/branches
featureX
featureY
/tags
1.0
2.0
The repository I'm working with is a much flatter structure.
trunk
featureX
featureY
Essentially, trunk is at the same level as the other branches. I can't use the -s or -b option with git svn init because of this.
How would I pull in trunk as the git branch master and pull in featureX as a git branch of the same name? I don't care about any other branches or tags.
I've seen similar questions and people have suggested restructuring the svn repository. This is off the table as far as this question is concerned.
I've figured out a way to pull in multiple branches from an arbitrary svn repository structure.
The
-boption forgit svn initwill only work if all branches are grouped together within a subdirectory in the repository, such as in the standard layout. If all branches, including the trunk, are side by side in the same folder, this won't really work. You can pull in selected branches from the svn repository by essentially creating multiple "trunks" int your git repository.Assume the flat structure from the question with the three branches trunk, featureX, and featureY.
Instantiate your git repository.
This will create a git repository with svn metadata in the
.git/configfile.Open the config file and examine the svn metadata
Your config file will look something like this.
The
svn-remoteheader defines a reference called "svn" pointing to your svn repository. Thefetchparameter tells git-svn where to pull new revisions from within the svn repository. Now we need to tell git-svn about the other branch we're interested in.Duplicate the
svn-remotesectionCopy the entire
svn-remotesection of the config file and paste it below the existing config text.Modify the new
svn-remotesectionChange the name of the
svn-remotesection header and the name of the branch that it points to.Now git-svn will track both svn branches. You can use the names "svn" and "svn-featureX" with any git-svn command that takes an
[svn-remote]parameter. You can use the names "trunk" and "featureX" with any git command that takes a remote branch name as a parameter.This solution won't scale well, and is a bit of a hack to work with a malformed svn repository. So long as you only need to track a handful of svn branches, this will work just fine. If the number of svn branches you need to work with becomes too large, take a serious look at restructuring your svn repository to the standard layout.