Add svn repo to existing git repo?
Solution 1
After searching last night, I have finally found the answer:
http://i-nz.net/2009/01/15/selective-import-of-svn-branches-into-a-gitgit-svn-repository/
It seems that you have to actually go in and manually edit the .git/config file in order to add an svn branch to an existing git repo. So according to these instructions I would have to add an entry for each branch.
Solution 2
The answers for this question (https://stackoverflow.com/a/840411 and https://stackoverflow.com/a/7592152) no longer work as of Git v1.8.3.2 (https://stackoverflow.com/a/19833311). You can do this instead:
1) Define the new branch in .git/config :
[svn-remote "release-branch"]
url = svn+ssh://[email protected]/source/branches/mono-2-2/mcs
fetch = :refs/remotes/git-svn-release-branch
2) Import the SVN branch. SVN_BRANCHED_REVISION is the the revision when the branch happened in SVN.
$ git svn fetch release-branch -r SVN_BRANCHED_REVISION
3) Create branch and hook up a local Git branch to the remote branch:
$ git checkout -b release refs/remotes/git-svn-release-branch
5) Update
$ git svn rebase
Solution 3
You can find the SVN_BRANCHED_REVISION by doing:
$ svn log --stop-on-copy PATH_TO_BRANCH
Solution 4
This is actually what git svn init does -- the other git svn commands simply merge things together, etc. You can git svn init and/or copy the layout of an SVN repo cloned with git svn clone, and you should just be able to pull into a local branch, or fetch, and so on. Have some time with the man page for git svn and you shouldn't have too much trouble piecing something together; if you do, #git on freenode is a good resource. So, this should be possible without too much trouble, but I don't know exactly how to do it all.
Related videos on Youtube
Comments
-
rip747 over 3 years
I know you can track a svn repo with git by using git svn init, however that is for if you want to create a brand new repo.
My situation is that I currently already have an existing git repo and want to track the trunk of a svn repo by making it a remote branch in my current git repo.
Any suggestions?
-
Luís Bianchin about 8 yearsI guess this answer is also valid here: stackoverflow.com/a/1430782/1046584
-
Caleb over 5 yearsPlease consider changing the accepted answer to this question, latest
git
versions no longer allow the version that worked for you initially. This answer has a current working solution.
-
-
Jody Garnett almost 13 yearsI found this one helpful: * blog.tfd.co.uk/2008/11/21/adding-a-branch-to-git
-
Jaime Hablutzel about 10 yearsIt could have stopped working from Git v1.8.3.2, see stackoverflow.com/questions/19712735/…
-
Elmer over 7 yearsit stopped working as of git v1.8.3.2, see answer stackoverflow.com/a/38706530/3303668 for an updated solution
-
Caleb over 5 yearsThis should probably be marked as the correct answer. The current checked answer does not work on current git (2.18.0), this does. The other answers have minor issues that stop it all from coming together. This does what the question asked about.
-
Joshua Detwiler almost 3 yearsFrom what I can gather, this "refs/remotes" notation is specific to how git names remote repos/branches? So if I wrote in the config
:refs/remotes/my_git_branch_name
, this is how git would track the branch? Is that correct?