tags:

views:

2598

answers:

4

How can i fork and keep in sync with an google code svn that i dont have write access to,into a github repos. I want to be able to develop own features in my git but also want to sync against the google code svn.to fetch fixes from google code project side. I know about git-svn and used it before to up and downstream to an svn repos i had full controll over. But i dont know how keep in sync with an google code svn.

+1  A: 

Hmm.. In my company I was doing nearly the same. Just having both .svn and .git repo in the same directory (you checkout svn repo and create git repo in this working copy).

Then using svn up and git push did the thing. Of course if you diverge a lot you'll have to merge things by hand.

Marcin Gil
Ja right, but i want to avoid having the .svn meta data and was hoping that git is able to use an svn repos as down stream master
optixx
So isn't it possible to use git-svn to checkout repo and git push to github?
Marcin Gil
+40  A: 

The remote branch from git-svn is pretty much the same as a regular git remote. So in your local repository you can have your git-svn clone and push changes out to github. Git doesn't care. If you create your git-svn clone and push the exact same changes out to github, you'll have an unofficial mirror of the google code repository. The rest is vanilla git.

git svn clone http://example.googlecode.com/svn -s
git remote add origin [email protected]:example/example.git
git push origin master

Now that you have this, occasionally you will have to sync the svn repo with git. It'll look something like:

git svn rebase
git push

In gitk or whatever, this would look something like this:

o [master][remotes/trunk][remotes/origin/master]
|
o
|
o

And when you run git svn rebase, you would have this:

o [master][remotes/trunk]
|
o
|
o [remotes/origin/master]
|
o
|
o

So now running git push would push those commits out to github, the [remotes/origin/master] branch there. And you'd be back to the scenario in the first ASCII art diagram.

The problem now is, how do you work your changes into the mix? The idea is, you don't ever commit onto the same branch that you are git-svn-rebase-ing and git-pushing. You need a separate branch for your changes. Otherwise, you would end up rebasing your changes on top of the svn ones, which could upset anyone who clones your git repository. Follow me? OK, so you create a branch, let's call it "features". And you make a commit and push it out to github to the features branch. Your gitk would look something like this:

o [features][remotes/origin/features]
|
o
|
o [master][remotes/trunk][remotes/origin/master]
|
o

Here you've got your features branch a couple of commits ahead of the Google Code branch, right? So what happens when you want to incorporate new stuff from Google Code? You'd run git svn rebase first and get this:

                           o [features][remotes/origin/features]
[master][remotes/trunk] o  |
                        |  o
                        o /
                        |/
                        o[remotes/origin/master]
                        |
                        o

If you git push master out, you can imagine the [remotes/origin/master] being at the same point as master. But your feature branch doesn't have the changes. Your choices now are to merge master into features, or rebase features. A merge would look like this

git checkout features
git merge master 

            o [features]
           /|
          / o [remotes/origin/features]
[master] o  |
         |  o
         o /
         |/
         o
         |
         o

Then you push features out to github. I've left off the remotes for master to save space, they'd be at the same point as [master].

The rebase approach is slightly more evil - you'd have to push with --force as your push would not be a fast-forward merge (you'd pull the features branch from under someone who had cloned it). It's not really considered OK to do this, but nobody can stop you if you are determined. It does make some things easier too, such as when patches get accepted upstream in slightly reworked form. It'd save having to mess about with conflicts, you can just rebase --skip the upstreamed patches. Anyway, a rebase would be like this:

git rebase master features

         o [features]
         |
         o
         |  o [remotes/origin/features]
[master] o  |
         |  o
         o /
         |/
         o
         |
         o

And then you would have to git push --force that. You can see why you need to force it, the history has a big old schism from the [remotes/origin/features] to the new current post-rebase [features].

This all works, but it is a lot of effort. If you are going to be a regular contributor, the best bet would be to work like this for a while, send some patches upstream and see if you can get commit access to subversion. Failing that, perhaps don't push your changes out to github. Keep them local and try and get them accepted upstream anyway.

rq
A: 

I’m not quite sure what it is that you want but, of course can you pull from a subversion repository and push to a Git repository from the same working copy. And you can also git svn dcommit back to the subversion repository. You can’t make the GitHub repository sync against the subversion repository, though. Also, when you have commits in your working copy that are not yet in the subversion repository you will need to rebase them if the subversion repository was updated, forcing you to git push --force the “new” commits to GitHub.

Bombe
+1  A: 

A walk-through for synchronizing from Google Code to GitHub is available at fnokd.com. The author uses an always-on remote server and a cron job to automate the synchronization and keeps the SVN trunk in a GitHub branch called "vendor".

akaihola