Using TortoiseGit with svn-git to clone specific branches of SVN repository

I have a SVN project with following architecture (empty trunk and tags)

https://svn-repo.com/svn/company
   +--my_project
   |  +--trunk (empty)
   |  +--branches
   |  |  +--my_branch
   |  |  +--my_branch2
   |  |  +--temp_branch1
   |  |  +--temp_branch2
   |  |  +--temp_branch3
   |  +-tags (empty)

I would like to use TortoiseGit to clone this repository into a git repository with branches my_branch and my_branch2 and being able to commit changes back to SVN.

  • Find which commit does an object belong to?
  • How to clone all projects of a group at once in GitLab?
  • Why is comitting on a detached HEAD allowed at all?
  • How to cache github repos so 2nd git clone will use the cache instead of github repo
  • Why is it necessary to lose untracked files when you set up github pages?
  • iOS Cocoapod with git large file storage
  • I have been able to clone a single branch by not checking any boxes related to Trunk, Tags, Branch and putting the URL to the branch (e.g. https://svn-repo.com/svn/company/my_project/branches/my_branch) and specifying the first SVN revision of the branch.

    TortoiseGit clone of SVN single branch

    I have tried to put the URL https://svn-repo.com/svn/company/my_project and checking all the boxes but this failed each time.

    Question 1: How to clone the SVN repository with all its branches to Git through TortoiseGit?

    Question 2: What is the way (if it exists) to only keep certain branches in the Git repository (namely, removing all the branches temp_branchN)?

    I found a bit of if using git-svn CLI (like this related topic) but nothing relevant for TortoiseGit.

    Thanks a lot

  • How to tag a git revision and then listing tagged revisions
  • Jenkins Github Plugin - Triggering a Parameterized Build
  • How to push your local master branch to Heroku when you've already pushed a feature branch?
  • How can I store keychain credentials for multiple Github accounts?
  • What does git mean?
  • How did I cross the streams, and how can I uncross them?
  • 2 Solutions collect form web for “Using TortoiseGit with svn-git to clone specific branches of SVN repository”

    1. You can’t do it (in good way) in pure TortoiseGit
    2. You have to edit [svn-remote] section in $GIT_DIR/config file by hand

    Git-SVN doc mention some rare cases for Subversion repos and suggest possible solution: enumerating all needed (and only needed) branches

    Since some SVN repositories are oddly configured with multiple projects glob expansions such those listed below are allowed:

    [svn-remote "project-a"]
        ...
      branches = branches/*/project-a:refs/remotes/project-a/branches/*
      branches = branches/release_*:refs/remotes/project-a/branches/release_*
      branches = branches/re*se:refs/remotes/project-a/branches/*
        ...
    

    Question 1 A mix of TortoiseGit + patch of config file (c.f. below)

    Question 2 Based on Lazy Barger hints, I came up with the following flow

    1. TortoiseGit clone with only a selection of the trunk (revision 12345 corresponding to the creation of the tunk)

    TortoiseGit clone of SVN trunk

    1. .git/config file edited by hand to add the desired branches

    The following shall be added in the svn-remote part

    [svn-remote "svn"]
        url = https://myserver:8443/svn/WorkRoot
        fetch = my_project/trunk:refs/remotes/origin/trunk
        branches = my_project/branches/my_branch*:refs/remotes/branches/*
    
    1. TortoiseGit SVN fetch to pull out the branches

    The last command might take a while because it starts searching from revision 1.

    1. Perform TortoiseGit Switch/Checkout to change the branch

    Note: To perform the command equivalent to svn update, I use Git SVN Rebase and select the correct upstream corresponding to the remote branch (and not the trunk which is selected by default).

    Git SVN Rebase

    Hope it helps

    Git Baby is a git and github fan, let's start git clone.