Using Git with R-Forge OR Adding an local Git branch to track an Subversion Repo

These instructions were originally from instructions from my friend Charlie.

I really like to use Github but R-Forge has alot of nice features for package development, so why not get the best of both worlds.

Say you have a git repo (with an R package or something else) but want to create a local brach which tracks an svn repo (from R-Forge) such that you can merge changes from your git repo in and then commit them to svn. First use the following command to grab the current svn:

cd my-r-package
git svn clone svn+ssh://developername@svn.r-forge.r-project.org/svnroot/my-r-package .

This will create a new git repository that is a mirror of whatever svn repo you pointed at. This may take a while if you have a big existing svn repo.

If you want to add a svn bound branch to an existing git repo:

Edit .git/config and add the following:

[svn-remote "r-forge"]
  url = path/or/url/to/svn/repository
  fetch = :refs/remotes/r-forge-svn

Once you’ve done this, you have created an entry for a new git remote server- fetch the status and history of it’s branches using the following:

git svn fetch r-forge

If this command is successful, git branch -a should show:

r-forge-svn

In the list of available branches. This branch is a remote branch- to make a local copy, do the following:

git checkout r-forge-svn
git checkout -b r-forge-svn-local

Now you have a local branch which is bound to the svn server- once again straight up adding/removing/moving files in this branch should work fine. It’s merging that gets you into trouble.

How to merge between a git branch and a git-svn branch

The point is that you don’t want git infecting your subversion repository with any of its awesomeness. Exposure to the kind of concentrated badass possessed by git causes poor SVN’s head to pop. So, the merge must be done as follows:

git checkout r-forge-svn-local
git merge –squash branch-to-merge-in

The --squash option tells git to leave out any info about what happened during the merge and act like it just mashed a bunch of files into your svn branch using copy commands.

Once you’ve added/copied/moved/squashmerged new files into your local svn branch- do the following to push the changes to the svn repo:

git commit -a               (Commit changes to your git repo as normal.)
git svn dcommit           (This will form each git commit into a svn commit and send it to the svn repo)

To pull changes from the svn repo run the following:

git svn rebase

11 thoughts on “Using Git with R-Forge OR Adding an local Git branch to track an Subversion Repo

  1. Thanks for sharing these instructions. I too would like to take advantage of R-forge while using git at the same time.

    I have not started my package yet, but I expect to do it soon.

    A question: suppose I start writing the package first and use git on my computer. I then sign up for R forge. What do I do for my first upload? Start with the instructions “Edit .git/config?”

  2. I signed up for an R-forge account and started a project there. I put the following in .git/config:

    [svn-remote "r-forge"]
      url = svn+ssh://MYUSERNAME@scm.r-forge.r-project.org/svnroot/inference
      fetch = :refs/remotes/r-forge-svn</p>

    When I enter git svn fetch r-forge I get the following error:

    Could not chdir to home directory /var/lib/gforge/chroot/home/users/nguyenvq: No such file or directory
    Couldn’t find a repository: No repository found in ‘svn+ssh://nguyenvq@scm.r-forge.r-project.org/svnroot/inference’ at /usr/lib/git-core/git-svn line 1765</p>

    I figure this is because my SVN repository is currently empty. I type git svn dcommit and get:

    Unable to determine upstream SVN information from HEAD history.
    Perhaps the repository is empty. at /usr/lib/git-core/git-svn line 517.

    Help? Thanks.

  3. I just redid and things are working up to this point:

    $ git merge –squash branch-to-merge-in
    fatal: ‘branch-to-merge-in’ does not point to a commit

    Thoughts? Thanks.

  4. is branch-to-merge-in a branch you have created with changes committed to it? For me it is usually the master branch from github.

  5. I think I’m a little confused. Does your instructions include the use of github? I’m just trying to use git and R-forge. How would the instructions change then?

    After reading your blog multiple times, this is what I think the process should be like:

    1. Clone svn from R-forge (will have www and pkg directories).
    2. Set up r-forge-svn and r-forge-svn-local branches (is this needed if I don’t use github?).
    3. git add files, make changes.
    4. git commit.
    5. git svn commit.

    Let me know your thoughts. I’m new to both git and R-forge. Thanks.

  6. So I use git to push to github but there is no reason that you would need to do that. Though if you don’t use it, it is an excellent tool that I recommend. I would put the process more like:

    1. Clone svn from R-forge (you may only want to clone the pkg directory but that is up to you). If you already have a git repo then you dont need to do this.
    2. Set up r-forge-svn and r-forge-svn-local branches.
    3. Create a new git branch and do all your work with that or branches off of that, call it “master” (git checkout -b master). Add files and make changes to the master branch.
    4. Commit to the master branch.
    5. Checkout the local r-forge-local branch and merge in your changes (git merge --squash master) and commit the merge (git commit -a)
    6. Then commit to the svn repo from the r-forge-local branch (git svn dcommit)
    7. Switch back to the the master branch (git checkout master) and go on working as usual.

    My apologies if the post is not as clear as it could be, I assure you it works once you get it set up.

    For a reference if it helps here is my .git/config for pgfSweave:

    [core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
        ignorecase = true
        autocrlf = false
    [remote "origin"]
        fetch = +refs/heads/*:refs/remotes/origin/*
        url = git@github.com:cameronbracken/pgfSweave.git
    [branch "master"]
        remote = origin
        merge = refs/heads/master
    [svn-remote "r-forge"]
        url = svn+ssh://cameronbracken@svn.r-forge.r-project.org/svnroot/pgfsweave/pkg
        fetch = :refs/remotes/r-forge-svn

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>