Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use local Git repository with a master Subversion repository

Tags:

git

svn

I have heard that it is possible to have a local Git repository on a developer machine, while keeping a master copy of the source code stored in a svn repository.

A good use case would be that you have a central svn repository that each developer works with. One developer goes offline occasionally and would like to track changes he/she makes while offline. When the developer is back online and has access to svn, their working copy modifications could be checked into svn. I'm fine with losing the history of changes that happened locally with Git, when the files are checked into svn.

Can someone outline how best to pull this off? Are there any pitfalls to working like this?

like image 391
Jim Geurts Avatar asked Aug 12 '09 19:08

Jim Geurts


People also ask

Can you use git and SVN together?

git-svn is a specialized tool for Git users to interact with Git repositories. It works by providing a Git frontend to an SVN backend. With git-svn, you use Git commands on the local repository, so it's just like using normal Git. However, behind the scenes, the relevant SVN commands are sent to the server.

How do I clone a local repository in SVN?

# Clone a repo with standard SVN directory layout (like git clone): git svn clone http://svn.example.com/project --stdlayout --prefix svn/ # Or, if the repo uses a non-standard directory layout: git svn clone http://svn.example.com/project -T tr -b branch -t tag --prefix svn/ # View all branches and tags you have ...


2 Answers

You could use something like this tutorial as a starting point. I also read this tutorial.

There are several pitfalls to this mode of working. The most important one is that you cannot be using svn version 1.5 mergeinfo and expect this to survive through git. This is a major drawback if you're using the (arguably fairly decent) svn 1.5 merge functionality.

The man page for git-svn also contains some notes under the "caveats" that section that you should understand. Once I understood all the caveats I understood the benefits of using this setup to be less than the actual cost for my specific case. So I used my energy to convince the project to switch to git instead, something I just succeded in.

like image 55
krosenvold Avatar answered Oct 03 '22 22:10

krosenvold


Say your SVN repo is at svn+ssh://username@svn_server/svn/your_repo
and your SVN repository has a "proper" layout (trunk, branches, tags) Here's workflow I've been using for few months now:
1. 'mkdir your_repo'
2. 'cd your_repo'
3. 'git svn clone -s svn+ssh://username@svn_server/svn/your_repo .' (mind the dot)
4. [wait a while depending on the size of your repository :)]
now your GIT 'master' tracks the SVN trunk
you can also make a tracking branch like you'd normally do with git if you're working on some branch
5. the traditional hack hack hack
6. update your clone with 'git svn fetch && git svn rebase'
7. "push" your changes to svn with 'git svn dcommit'

More good stuff
Define following handy aliases in your .gitconfig:
1. Alias 'spull' which stands for svn-pull like this: 'spull = !git svn fetch && git svn rebase'
2. Alias 'spush' which stands for svn-push like this: 'spush = !git svn dcommit'
These aliases turn the workflow in to pure effectiveness: clone/hack hack/spull/spush -> profit

svn:externals
I couldn't find a good solution for this in the internet, so made one myself :)
http://github.com/sushdm/git_svn_externals it's not yet perfect, but it should definetely make life a lot easier.

Works for me perfectly well, hope it helps you.

like image 27
Dmitry Avatar answered Oct 03 '22 22:10

Dmitry