Skip to content

svn to git quickstart

Leif Walsh edited this page May 17, 2013 · 2 revisions

svn to git quickstart

Quick instructions for getting up to speed with git. There are plenty of tutorials for doing exactly this that go in to more depth, this will be brief. Probably start with Git - SVN Crash Course.

  • svn checkout https://svn.tokutek.com/tokudb/mongodb.org/mongodb-2.2-tokutek/ => git clone git@github.com:Tokutek/mongo.git
  • svn copy https://.../mongodb-2.2-tokutek/trunk https://.../mongodb-2.2-tokutek/branches/7000 => git branch 7000
  • svn up => git pull
  • cd ../branches/7000 => git checkout 7000
    • create a branch and switch to it at the same time with git checkout -b 7000
  • cd ../../trunk => git checkout master
  • svn merge -rXXX:HEAD ../branches/7000 . => git merge 7000
  • incorporating changes on master (trunk) into a branch (in svn, this would be create 7000b from trunk, and merge 7000 onto 7000b) => git checkout master; git pull; git checkout 7000; git rebase master (if you want to rebase) or git checkout master; git pull; git checkout 7000; git merge master (if you want to merge recent things from master into 7000)

Probably the biggest differences between git and svn are these three:

  1. When you're ready to commit, you have to git add each file that you want to be part of this commit, and then commit it (with git commit). You have to do this every time you make a commit. You can use git commit -a to commit anything that git was tracking before that has changed, and this is similar to svn commit, but the idea is that you shouldn't commit something accidentally if you manually add each change. You can also add a portion of the changes in a file to a commit.
  2. When you commit, you're just recording that commit locally. When you're ready to send things up to the server, you have to do git push, and if there have been changes on the server since you last did a git pull, you'll have to do git pull; <resolve any merge conflicts>; git push.
  3. Branches don't live in separate directories. The repository lives in the .git/ folder, along with all the history and all the branches, so when you do git checkout <branchname> it's actually wiping out the current working directory and filling it with the other branch you're switching to, so you switch branches "in-place".

Because committing and branching are cheap, local operations, you're encouraged to branch and commit much more frequently than in svn (there are ways to merge lots of tiny commits into a larger commit for public consumption if you want), even if something's broken.

Clone this wiki locally