1. Working with Git and SVN Repository

    Posted by Vinay on January 15, 2011 in Git

    Lately I have been working on some projects where the files are hosted in svn repository, and since git has built in support for svn, it was a breeze to set it up. Clients use Versions to commit/log the changes and UnFuddle is where all the svn source files are hosted.

    Some of the git commands are different when working with svn. The basic changes are

    git clone  => git svn clone -s

    git pull 
    => git svn rebase

    git push 
    => git svn dcommit 

    Cloning the svn repo using Git

    The First and foremost step is to Clone the SVN Repository to your local machine using git-svn clone. Given that you have created your repository in Unfuddle.

    git svn clone -s http://project.unfuddle.com/svn/project_repo/ 

    Git will create a full clone of your svn repository with all the branches, trunks and tags

    Setting up .gitignore

    Set up your gitignore file as normal. I usually have the following in my .gitignore file

    .DS_Store
    .gitignore 

    Create a Branch and Committing

    I usually dont do this, unless i am creating a new feature for the application. Eg: A javascript carousel, or a new user authentication system. You can work as per normal with the files and when ready to commit, use

    git commit --"Modified aa.html and added a smiley face :)" 

    Before i push the files to the svn remote repo, i always make sure to update my local files using git svn rebase. I will fix any conflicts that may occur and push the files to remote svn using

    git svn rebase
    git svn dcommit 

    Git Stash

    Git stash has been my livesaver for all my projects. Lets say you are work on something important(A.html) which is like half complete,  and your collegue says “He there is a bug in one of your files(B.html), can you fix that ?”.  I dont want to commit my A.html changes since it is a uncompleted version. I use git stash here which records the changes in A.html and goes back to clean working directory. Now i make the edits to B.html, commit it and push it the svn repository. When i am done with fixing the bugs, i take back A.html using:

    git stash apply 

    It will bring back all the changes i had done to A.html and i am ready to roll.

    Reverting a file

    It works the same way as in git

    git checkout -- filename 

    These are some of the basic commands i use to manage svn repository with git. No complex stuff here.