22

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 examples I have able to find talk about using svn switch as method to switch location instead of actual branches.

Essentially, I would like to start pulling from /svn/branch/1.3 instead of /svn/branch/1.2 using svn fetch.

Community
  • 1
  • 1
Jauder Ho
  • 1,345
  • 1
  • 16
  • 22

4 Answers4

21

These commands have been incredibly useful for me when working on svn branches via git-svn:

#create local Git branch that mirrors remote svn branch

git checkout -b local/RELEASE-0.12 RELEASE-0.12 
#will connect with a remote svn branch named ‘RELEASE-0.12′

# -n will show which svn branch you will commit into:
git svn dcommit --dry-run 

See full explanation in my article on justaddwater.dk.

l0b0
  • 55,365
  • 30
  • 138
  • 223
Jesper Rønn-Jensen
  • 106,591
  • 44
  • 118
  • 155
  • 3
    I was able to do this but my syntax was different `git checkout -b branchname origin/branchname` – Mike D May 20 '15 at 23:50
7

If you've cloned the SVN repository properly (using -T -b -t or -s), you should be able to use the git branch commands like:

git reset --hard remotes/branch

git checkout branch

etc.

Can Berk Güder
  • 109,922
  • 25
  • 130
  • 137
  • What if I already have changes in my local repo that I push to a separate git repo on github? I created the repo originally using git svn clone http://svn/branch/1.2 – Jauder Ho Apr 08 '09 at 08:41
  • git checkout branch doesn't destroy your changes. git reset --hard does. – Can Berk Güder Apr 08 '09 at 08:45
  • If you use reset --hard here, you'll blow away any changes made locally on top of remotes/branch. – richq Apr 08 '09 at 08:51
  • I do not own the svn repo and apparently only the branches are exposed (as releases). So this is not really a duplicate of the other request. In this scenario, I am not able to do a git branch -r followed by git checkout -b – Jauder Ho Apr 08 '09 at 09:11
  • Basically, git branch -r does not show the 1.3 branch just stuff under the 1.2. – Jauder Ho Apr 08 '09 at 09:14
  • How is the SVN repo structured? – Can Berk Güder Apr 08 '09 at 09:26
  • Now that's a weird one. A repo like this normally calls for git svn clone http://svn.magentocommerce.com/source -b branches, but http://svn.magentocommerce.com/source returns HTTP 403, so that probably won't work. – Can Berk Güder Apr 08 '09 at 11:02
  • That's my point, they have a strange setup and I've been trying to figure how to work around it. – Jauder Ho May 23 '09 at 05:08
0

From my experience, it works fine doing just

git checkout -b RELEASE-0.12 RELEASE-0.12

The local/ prefix is not needed, and it is less confusing to me to leave it out. The old RELEASE-0.12 branch is already a remote branch, so git will not confuse it with the new branch.

The command above will not create a tracking branch relationship. But that is not needed, git svn rebase works as expected anyway.

Klas Mellbourn
  • 42,571
  • 24
  • 140
  • 158
0

A lot of the answers here and in the linked duplicate assume that the initial git svn init/git svn clone used the -T -b -t or -s parameters to link to an svn project structure. In those cases, a git checkout -b is sufficient to switch between the branches that the initial init/clone linked up between your git and svn repositories. git branch -r will even show you the svn linked branches that you can switch to.

If the initial init/clone was directly to a specific SVN branch, though (as the OP question suggests), then I think the .git/config file needs to be updated directly:

[svn-remote "svn"]
    url = https://svn/branch/1.3
    rewriteRoot = https://svn/branch/1.2
    fetch = :refs/remotes/git-svn
Shiraz
  • 2,310
  • 24
  • 26