How do I access svn branches using git-svn with a non-standard svn repo layout?

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.

-------------Problems Reply------------

I've figured out a way to pull in multiple branches from an arbitrary svn repository structure.

The -b option for git svn init will 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.

  1. Instantiate your git repository.

    mkdir myproject
    cd myproject
    git svn init url:to/svn/repo -T trunk

    This will create a git repository with svn metadata in the .git/config file.

  2. Open the config file and examine the svn metadata

    vim .git/config

    Your config file will look something like this.

    [core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    autocrlf = false
    [svn-remote "svn"]
    url = url:to/svn/repo
    fetch = trunk:refs/remotes/trunk

    The svn-remote header defines a reference called "svn" pointing to your svn repository. The fetch parameter 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.

  3. Duplicate the svn-remote section

    Copy the entire svn-remote section of the config file and paste it below the existing config text.

    [core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    autocrlf = false
    [svn-remote "svn"]
    url = url:to/svn/repo
    fetch = trunk:refs/remotes/trunk
    [svn-remote "svn"]
    url = url:to/svn/repo
    fetch = trunk:refs/remotes/trunk

  4. Modify the new svn-remote section

    Change the name of the svn-remote section header and the name of the branch that it points to.

    [core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    autocrlf = false
    [svn-remote "svn"]
    url = url:to/svn/repo
    fetch = trunk:refs/remotes/trunk
    [svn-remote "svn-featureX"]
    url = url:to/svn/repo
    fetch = featureX:refs/remotes/featureX

    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.

As this article illustrates, you can write rules for running an importer tool like svn2git
(you have less complete version of svn2git here)

See those examples for rules that you could rewrite in order to match those flat SVN directories/branches and declare them as Git branches.

Category:branch Views:2 Time:2010-09-09

Related post

  • How can I track multiple svn branches in git 2009-01-19

    There are so many ways to skin a cat, can anyone improve on this? --------------Solutions------------- That's a great article, but what really helped me was to understand the config for git svn. Assuming your SVN is setup like: $SVN_ROOT/project/trun

  • How to switch svn branches using git-svn? 2009-04-08

    Duplicate How do I make git-svn use a particular svn branch as the remote repository? I am using git-svn to track development by someone else on svn. I'm trying to figure out how to use gti-svn to switch from one svn branch to another. All the exampl

  • Delete a svn-Branch via git? 2009-12-03

    I'am using git as scm of choice but have to use a svn-repo. I can create a svn-remote-branch like this: git svn branch the_branch But how can i delete the remote branch? --------------Solutions------------- Currently, it is not possible to delete an

  • Can you specify which svn branches with git svn? 2009-01-15

    I think my question is somewhat similar to CaptainPicard's but dissimilar enough that I feel compelled to ask so here goes. I have an old SVN repository with around 7500 revisions and part of those 7500 revisions are some pretty large .fla files. And

  • Importing an svn branch into git 2009-02-05

    I am new to git, and have a subversion repository that I want to be able to import into a git repository occasionally (for deployment). So I want to perform most of the updates using svn but wanted to see what's the best way to push it to git (just t

  • create a new svn branch with git-svn 2010-03-29

    While working with git-svn, and a 'typical' svn repo /trunk, /branches/..., /tags/... How do I push a local branch to a new branch inside of /branches ? --------------Solutions------------- Say we have a skeleton Subversion repository with empty trun

  • Problem cloning a single SVN Branch via git svn 2010-08-20

    I have tried the following command on my SVN Repository to clone only a single branch via git. git svn clone http://svn.supose.org/supose/branches/B_0.7.1 but got the the following error message: Initialized empty Git repository in /Users/km/workspac

  • How to integrate svn branches into git branches with git-svn? 2011-03-02

    i have not much svn experience but i am used to work with git. I have the following svn repository structure and revisions. https://server/svn/solution/trunk/solution.sln @r100 https://server/svn/solution/trunk/project1/project1.csproj @r150 https://

  • how do I export svn repository to git when I don't have svn credential? 2011-07-15

    I have a full checkout of svn repository in a folder. But I don't have the credentials of the svn repository(hosted in Unfuddle). I want to move this folder to a new git repostitory ( Github) with all its history and changes intact . If possible I wo

  • How can I find what SVN branch my git branch will dcommit to? 2012-01-19

    How can I check what branch "svn dcommit" from my currently checked out branch is going to push to? --------------Solutions------------- git svn info will include the URL of the Subversion repo your git branch tracks. $ git svn info Path: . URL: svn+

  • git svn imported repository using svn branches 2010-08-24

    I've cloned a replicated svn repository (svnsync to local file system). All the branches etc. are now available in git. Now i would like to start working on svn branches git checkout remotes/B_XYZ and doing some commits via git. Now i want to change

  • How do I make git-svn use a particular svn branch as the remote repository? 2008-10-10

    A word of warning: I'm a n00b to git in general. My team uses feature branches in svn, and I'd like to use git-svn to track my work on a particular feature branch. I've been (roughly) following Andy Delcambre's post to set up my local git repo, but t

  • How to make an existing git branch track a remote SVN branch? 2010-07-22

    Similar to this question, how can I make an existing Git branch track a remote SVN branch? I often find that I start work in a local branch that I then need to push to an SVN server. Is this possible? --------------Solutions------------- The idea rem

  • No longer track branches with git-svn 2011-01-25

    I have cloned a svn branch using git-svn and am tracking all folders and branches. I would like to drop everything and only track web/trunk/* (for rebase, dcommit, etc.) Is there any way to do this without reinitializing the repository? -------------

  • Create an SVN branch from an existing Git branch 2011-03-11

    I have cloned an existing SVN project via git svn clone with no problem so far, but in the mean time I have created a branch in Git only (not in SVN) and now i would like to synchronize this branch back to an SVN branch (not the trunk). I have create

  • Branching with Git and SVN 2012-02-02

    I cloned an SVN repository down and I've been working on master - checking things in locally - but I haven't yet pushed to SVN. Now, I've decided I want to push my local changes "on master" to a new SVN branch (not to the main trunk). What is the bes

  • How can you indicate files to ignore in svn when using git and the git-svn bridge? 2010-05-12

    There is a master subversion repository that I've cloned a git repo from. I've got a lot of ignored files in my .gitignore that I'd like the svn repository to know about. I know that I can use git svn show-ignore to pull the ignored list from subvers

  • Converting svn to git, how to get the branches not to be just remote in the svn repo? 2009-10-18

    I'm quite new to git and I'm trying to move a svn repository to git. I followed the guide below so now I have a git repo on my server http://pauldowman.com/2008/07/26/how-to-convert-from-subversion-to-git/ So, if I do "git branch" git replies "* mast

  • Grafting a Git history onto an SVN branch 2008-09-22

    The situation I have a Git repo and an SVN repo that both hold the same source code but different commit histories. The Git repo has a lot of small well commented submits... while the SVN repo has a few huge commits with comments like "Lots of stuff"

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.094 (s). 11 q(s)