Wednesday, June 3, 2009

A Brief Git Tutorial for Subversion Users

The following is just a barebones config and partial comparison of git to svn that might substitute for a tutorial. There are others like Git - SVN Crash Course that are better, but they don't mention the pushes, so I thought I'd include those here.

Repo Creation

(info from Richard)
* https://37s.backpackit.com/pub/1465067

Use the "git --bare init --shared=group" command.

See also: http://git.or.cz/course/svn.html

Client Installation (for OS X 10.5 Leopard)

Option 1 - Download from Google Code

A little older version, but it doesn't matter much Jim said:
* http://code.google.com/p/git-osx-installer/

Option 2 - Building Locally

Download Git (the tar.gz. it is source + build version)

Followed the directions here for install via using Fink and building from source with version 1.6.2.4 (replace their version# with that one).

Make sure you are no longer root when done, although you probably just did sudo.

Configuration

git config --global user.name "Your Name"
git config --global user.email "your@email.address"

SVN vs. Git

svn co ...git clone ...Note that you are checking out the whole repo and revision history, not just current partial of the repo like svn.
cd (path to branch)git checkout remote-branch 
cd (path to trunk)git checkout master 
cd (path to tag)git checkout tag-nameUnlike subversion, a tag is not just like a branch or trunk. It is only a tag, so you can't treat it like a branch like you can in svn.
1. cd (path to tags)
2. ls
git tag -l 
1. cd (path to branches)
2. ls
git branch git branch just lists local branches. git branch -a lists local and remote branches. git branch -r lists remote branches.
svn addgit add 
svn delgit rm 
svn mvgit mv 
svn commit -m "message"1. git add ...
2. git commit -m "message"
3. git push origin remote-branch
In git, you must git add modified files, and the change is not shared until it is pushed. Remember you have a local copy of the repo. You can git commit -am "message" to bypass having to add files already in the repo that were modified. Git push by itself by default will push all local branches that match remote branches, unless using Git 1.6.3+ and then behavior is defined by push.default in git config.
svn diffgit diffIn Git, after you add, etc., diff returns that now nothing is different, even if you haven't pushed (shared) changes yet.
svn upgit pull origin remote-branchNote that conflict resolution is a bit more featureful in git.
svn loggit log 
svn log -vgit log --rawGit provides a little more info in --raw that you might not want.
svn copy url tag-url1. git tag -a name
2. git push --tags
Git push without --tags doesn't push tags.

To make git pulling and pushing less error-prone, you might try the gpull and gpush aliases provided by Cody Caughlan. In ~/.bash_profile, add:

# provided by Cody Caughlan in http://stackoverflow.com/questions/948354/git-push-current-branch
get_git_branch() {
  echo `git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
}
alias gpull='git pull origin `get_git_branch`'
alias gpush='git push origin `get_git_branch`'
More Info:
* Git cheat
* Git push current branch
* Git for the Lazy
* Git for Computer Scientists
* Git from the Bottom Up
* Git - SVN Crash Course
* Git_Guide

No comments: