Add an SVN remote to your Git repo
I love git. Who doesn't? I'll tell you who: larger companies with an existing infastructure that revolves around SVN. Luckily you can still reap some of the git-benefits by adding svn-remote branches!
You can clone an entire SVN repo (trunk, branches, tags):
$ git svn clone https://myrepo.com/svn -T trunk -b branches -t tags
But sometimes we're in a hurry and only grab the trunk. What now? With the help of Ian Boston, I learned how to add remotes / branches after I've initialized my git-svn repo.
Adding Branches to an existing git-svn repo
-
Edit the .git/config to add an svn-remote:
[core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true [svn-remote "svn"] url = https://myrepo.com/repos/projectName/trunk fetch = :refs/remotes/git-svn [svn-remote "svn2"] url = https://myrepo.com/repos/projectName/branches fetch = :refs/remotes/git-svn-mybranch
-
Fetch the branch via terminal. "-r" followed immediately by a valid revision number will only fetch from that revision, but is optional. Say we wanted to fetch starting at revision 311 - So far so good? Don't believe me? Well fine, you can check to see if it worked by listing the branches.
$ git svn fetch svn2 -r311 $ git branch -a
-
Create/Switch branches
$ git checkout git-svn-mybranch $ git checkout -b master-mybranch