Friday, November 19, 2010

Getting started with Git

If you have a large shared software project and want an easy way to manage collaboration, branch off different versions of the project and generally keep things organized, you need a version control system. Git is the one I know (Mercurial and Subversion are also popular choices) and the one other people in the group are using, so it's the one I'll go over here.

Download git here: http://git-scm.com/download
Set up an ssh public key and register an account at github.com: http://help.github.com/mac-key-setup/ (apologies to non-Mac users)
Enter the following at the terminal (with obvious substitutions):

PATH=$PATH:/usr/local/git/bin/
export PATH
git config --global user.name "Your Name"
git config --global user.email your.email@something.com

To pull a repository called "repo" from user "person":

mkdir repo (or what have you)
cd repo
git init
git remote add origin git@github.com:person/repo.git
git pull origin master

In particular, every call of "git pull origin master" pulls the currest master version off github. Be sure you're working with the current version before trying to push local changes, or you might get conflicts. To commit changes, either call

git add files_that_changed
git commit

or

git commit -a

which commits all changed files. Committing brings up a text editor where you describe any changes made. Be aware, if you don't write anything the commit will be aborted. Then to push your changes from the local machine to github just type

git push

and that's it! Things get messier when working with branches, checkouts and merges, but for 90% of what I do the above suffices. The web abounds with tutorials and a quick reference sheet can be found here.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.