tags:

views:

339

answers:

3

I am new to git, and have a subversion repository that I want to be able to import into a git repository occasionally (for deployment). So I want to perform most of the updates using svn but wanted to see what's the best way to push it to git (just the default/master branch).

+3  A: 

Why not just work in git on your workstation too? That would be the most straightforward.

  • git svn clone will grab your SVN repository and import the revisions into a new git repo.
  • If you need to push to a remote git repository for deployment, then git remote add will add it for you.
  • If you need to push back to the SVN repository then git svn dcommit
Andrew Vit
+1  A: 

Hi, this tutorial will help you do that:

Simplistic Complexity

above link help text in a nutshell:

mkdir my_blog_tmp
cd my_blog_tmp
git-svn init http://code.yoursite.net/my_blog/trunk/ --no-metadata
git config svn.authorsfile ~/Desktop/users.txt
git-svn fetch

and congrats for joining us gits! Here is a great cheat sheet for (ex)svn users.

Ric Tokyo
+2  A: 

I know you only want to import the master/trunk branch of your svn repository, but I would like to mention svn2git in order to import your svn into a git repository.

It is better than git svn clone because if you have this code in svn:

  trunk
    ...
  branches
    1.x
    2.x
  tags
    1.0.0
    1.0.1
    1.0.2
    1.1.0
    2.0.0

git-svn will go through the commit history to build a new git repo.
It will import all branches and tags as remote svn branches, whereas what you really want is git-native local branches and git tag objects.
So after importing this project, you would get:

  $ git branch
  * master
  $ git branch -a
  * master
    1.x
    2.x
    tags/1.0.0
    tags/1.0.1
    tags/1.0.2
    tags/1.1.0
    tags/2.0.0
    trunk
  $ git tag -l
  [ empty ]

After svn2git is done with your project, you'll get this instead:

  $ git branch
  * master
    1.x
    2.x
  $ git tag -l
    1.0.0
    1.0.1
    1.0.2
    1.1.0
    2.0.0

Finally, it makes sure the HEAD of master is the same as the current trunk of the svn repo.

VonC