How to change the source version control from SVN to Git

Posted by itungnt on Monday, November 23, 2015

Today I created the Git repository from our SVN repository. Not too hard but need some techniques.

Check out from SVN and push to GIT

  1. From your workspace clone the svn trunk using git svn clone git svn clone YourSvnTrunkUrl

  2. Add remote git repository for pushing git remote add origin YourGitRepoUrl

  3. Push the master (trunk) to remote server git push -u origin master

  4. To clone 1 branch from svn. Change the .git/config to [svn-remote “svn”] url = YourSvnUrl fetch = trunk:refs/remotes/git-svn fetch = branches/YourSvnBranch:refs/remotes/YourLocalSvnBranch

  5. Fetch branches git svn fetch

  6. Create a local branch from SVN branch, then push to remote server git checkout -b YourLocalGitBranch remotes/YourLocalSvnBranch git push origin YourLocalGitBranch:YourBranchInGit

How to use git together with svn then you can check out from SVN then push to Git or vice versa

  1. Clone git into local git clone YourGitRepoUrl YourGitGolder

  2. Change the .git/config to [svn-remote “svn”] url = YourSvnUrl fetch = trunk:refs/remotes/svn/trunk fetch = branches/YourSvnBranch:refs/remotes/svn/YourBranch

  3. fetch from specific svn revision git svn fetch -r YourSVNVersion:HEAD

  4. if want to update the branch need to change git to the branch first git checkout YourGitBranch

  5. merge svn into git git merge remotes/svn/YourBranch git push

To merge conflict files you can use kdiff

  1. download [kdiff](http://sourceforge.net/projects/kdiff3/files/kdiff3/)
  2. set kdiff3 as mergetool git config –global merge.tool kdiff3 git config –global mergetool.kdiff3.cmd “"C:\Program Files\KDiff3\kdiff3" $BASE $LOCAL $REMOTE -o $MERGED"

comments powered by Disqus