61

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 those instructions seem to have led git to pick the svn branch that had changed most recently as the remote repository; the problem is that's not the branch I care about. How do I control which branch git-svn uses? Or am I approaching this completely wrong?

UPDATE: I did use the -T, -b, and -t options (in my case because the svn repo has multiple projects, but I want the git repo to contain only the project I'm working on).

avelis
  • 1,143
  • 1
  • 9
  • 18
Hank Gay
  • 70,339
  • 36
  • 160
  • 222

4 Answers4

60

Muchas gracias to Bart's Blog for this handy reference for svn branches in git. Apparently all I needed was to specify a remote branch when creating the git branch, e.g.,

git checkout -b git-topic-branch-foo foo

where foo is the name of the remote branch.

Hank Gay
  • 70,339
  • 36
  • 160
  • 222
  • 9
    If you already created your git branch, you can also use `git rebase` to rebase it onto the svn branch. – rampion May 03 '11 at 21:43
  • http://www.jukie.net/~bart/blog/svn-branches-in-git returns error 500. Has the blog moved or something? – Henry Jan 30 '13 at 00:57
  • Thank you, this seems to be the only way to get git to checkout a branch in non-detached state. – Shadow Man Jun 12 '13 at 18:33
  • 4
    The Bart blog is archived on archive.org: https://web.archive.org/web/20130119234635/http://www.jukie.net/~bart/blog/svn-branches-in-git – Reid Ellis Feb 11 '14 at 17:12
  • Even the archive for Bart's Blog is broken now. – Jim L. Jul 29 '15 at 13:29
  • @rampion But how do you create the empty svn branch in the first place? – Tom Dec 16 '16 at 06:48
  • 1
    @Tom OP's question assumed an existing svn branch. If you want to create an empty svn branch, use [`git svn branch $BRANCHNAME`](http://stackoverflow.com/questions/266395/git-svn-how-do-i-create-a-new-svn-branch-via-git). Note that not all your local git branches need to have a corresponding remote svn branch, just the ones you want to share. – rampion Dec 16 '16 at 09:04
30

You might also have a look at this: git-svn is a gateway drug - robby on rails.

I used something like this when I needed to make sure that my local branch was pointing to the correct remote svn branch:

git branch -r

to get the name of the remote branch I want to be tracking. Then

git reset --hard remotes/svn-branch-name

to explicitly change my local branch to point to a different remote branch.

Sam Mulube
  • 309
  • 3
  • 2
  • 1
    this is a manual process for forcing a local branch to update to the current state of a remote svn branch. the question as I read it has more to do with the remote tracking features of git and configuring git to automatically remote-track a specific branch in SVN. – David Alpert Feb 16 '12 at 15:59
10

I needed to run 'git svn fetch' first, since the branch I wanted to associate with had been created after my git client.

android.weasel
  • 3,343
  • 1
  • 30
  • 41
  • thanks, for this tip, and as a note, if found you can see the remotes in .git/svn/refs/remotes, and if there's a new one, after you run 'git svn fetch', it should show up there. – Alper Akture Aug 20 '13 at 23:34
  • careful about looking in .git, stuff in there can change. In particular, refs can be packed in packed-refs sometimes, particularly if they don't change much, and won't show up loose, even if they are present. git show-ref does this better, and (perhaps) git branch -r even better – ComputerDruid Aug 21 '13 at 14:26
  • 1
    if you run `get checkout -b git-topic-branch-name remote-branch-name` and get `fatal: git checkout: updating paths is incompatible with switching branches.` Then run `git branch -r`, and if you don't see the branch, that's when `git svn fetch` is needed. (`git svn rebase` won't pull the new branch, but `git svn fetch` will) – Stan Kurdziel Dec 12 '13 at 19:46
1

I use git-svn but I haven't used the features that interoperate with SVN branches. Having said that, I notice that the tutorial you were following didn't use the -T, -b, -t options to git svn init. These options tell git-svn what the upstream trunk/branches/tags directories are named, which might be important in your situation.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
  • Thanks, Greg. Unfortunately for me, that's the difference between my setup and the one in the blog. – Hank Gay Oct 12 '08 at 13:02