110 likes | 255 Views
Introduction to git. version control for serious hackers ;). Alan Orth Nairobi, Kenya September, 2010. The Problem. - One project, many developers... - Who fixed (or broke) what? - Exactly which changes fixed (or broke) feature X?
E N D
Introduction to git version control for serious hackers ;) Alan Orth Nairobi, Kenya September, 2010
The Problem - One project, many developers... - Who fixed (or broke) what? - Exactly which changes fixed (or broke) feature X? - How can we undo those changes easily (and log them, so that we don't forget!)
The Solution - Version control! - Many solutions over the years... - CVS (kitambo) - Subversion (was very popular until git) - Mercurial - Bazaar - I am biased, but git is the $%^!. - Written by Linus Torvalds (… heard of Linux?)
git practice $ mkdir test $ cd test $ git init . $ git status 1. Create a new directory 2. Move inside the new directory 3. Initialize the new directory as a git repository 4. Show the current status of the repository
git practice $ gedit hello.txt Type “Hello World” then save and exit $ git status git shows hello.txt as “untracked” Untracked files are files which are in the current directory but are not under version control!
git practice $ git add hello.txt $ git commit -m “Add hello.txt” $ git status $ git log 1. Add hello.txt to version control 2. Commit changes in current repository (-m tells git to save a “commit message” with this commit) 3. Show status of repository 4. Show the commit log (a sort of history)
git configuration Bio Sprint?! “Ammend” the last commit, telling git who you are: $ git commit --ammend --author=”Alan Orth <aorth@cgiar.org>” Make the settings permanent: $ git config --global user.name “Alan Orth” $ git config --global user.email a.orth@cgiar.org
Branching and merging - master: the main “branch” of development - Branches allow you to develop features and fix bugs without polluting (or destabilizing) the master - Many paradigms, but in git: branch early, branch often! - Crazy idea you want to try? Make a branch! If something breaks, just delete the branch :) - Otherwise, “merge” the branch back into master...
Branching and merging $ git branch goodbye $ git checkout goodbye $ git status 1. Create a new branch called “goodbye” 2. Switch to the new branch 3. Print out the status of the repository on the current branch. Note the [goodbye ] in the top left... we are on the “goodbye” branch!
Branching and merging $ gedit goodbye.txt $ git add goodbye.txt $ git commit -m “Add goodbye.txt” $ git checkout master $ git merge goodbye 1. Put text in goodbye.txt and then save and exit 2. Add goodbye.txt to version control 3. Commit changes to the current repository 4. Switch back to the master branch 5. “Merge” the changes from the “goodbye” branch into the current branch.
Getting Help - Don't RTFM, it is confusing and technical - Use google instead... there is always someone else who has already tried to do what you're trying to do! - Use git status frequently to see what's up - Use git diff to see what changes have been made - Use git branch to list branches in your repo - Pro git: http://progit.org/ A great, free ebook - Ask Alan?