Jauder Ho
Jauder Ho

Reputation: 1365

How to switch svn branches using git-svn?

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.

Upvotes: 22

Views: 16509

Answers (4)

Shiraz
Shiraz

Reputation: 2820

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

Upvotes: 0

Klas Mellbourn
Klas Mellbourn

Reputation: 44347

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.

Upvotes: 0

Jesper Rønn-Jensen
Jesper Rønn-Jensen

Reputation: 111576

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.

Upvotes: 21

Can Berk Güder
Can Berk Güder

Reputation: 113300

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.

Upvotes: 8

Related Questions