Git

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

http://git-scm.org

Preface

Unfortunately there's not enough time to teach you git, but maybe I can persuade you to siwtch anyway.

Distributed

  • Every repository is a complete copy
    • Everyone has a backup of all your code
    • Commands are super fast
    • Ability to work offline
  • Flexible Workflows

New Concepts

Staging Area

Changes go into a staging area before being committed. Convenient (commit some changes) but hard to get used to.

There are 3+ places for your code. Working directory (not commited), staging area (to be commited), local repo (commited), remote repo (shared).

Push/Pull

Committing doesn't means everyone has access to it. You need to push or have others pull your commits.

You also need to pull commits before you get access to them.

Branching/Merging

Branch early, Branch often

  • Branches are cheap!
    git checkout -b branch
  • Just a pointer to a commit
  • Merging is easy
    git merge branch
  • Merging Strategies
    • Fast-Forward
    • Recursive
    • Rebase
    • Octopus
    • Subtree

A successful Git branching model

Cool Stuff

Rebase

  • Lets you rewrite history
  • Avoid/Force merge commits

Before

* 7e927c8 - (HEAD, master) Finish docs (1 seconds ago) 
* 7762c6e - WIP (11 seconds ago) 
* f172078 - WIP (15 seconds ago) 
* bfbe19f - Start working on documentation (33 seconds ago) 
* 4e58868 - first commit (4 minutes ago) 

After

* 8381ad8 - (HEAD, master) Finish docs (14 seconds ago) 
* bfbe19f - Start working on documentation (5 minutes ago) 
* 4e58868 - first commit (8 minutes ago) 

Bisect

When did feature X stop working?

Specify a good commit and a bad commit, git will do a binary search between the two for the first commit that's bad.

git bisect start
git bisect good HEAD~7
git bisect bad HEAD

Bisecting: 3 revisions left to test after this (roughly 2 steps)

Demo if time (remind me!)

Git Hooks

Run scripts before/after git events:

  • pre-commit
    • Code linting
    • Enforce coding standards
  • post-commit
  • post-checkout
  • post-merge
  • post-recieve
    • Continuous ingegration
    • Automated deploys
  • much more...

Github

  • Hosted Git
  • Features
    • Repo browser
    • Issues
    • Wiki
    • Network/Graphs
    • Pull requests
    • Github pages
    • Online editor

Service Hooks

  • Web Hook
    • Ping URL when pushing to GitHub
    • Continuous ingegration
    • Automated deploys
  • Basecamp
  • Bugzilla
  • Campfire
  • Email
  • Fisheye
  • IRC
  • Jabber
  • much more...

Alternatives

  • BitBucket
  • Gitosis/Gitolite
    • Access control for bare repositories on a server
  • Gitweb
    • Web based repo browser

Learning Git

Basic Commands

git init
git add .
git status
git commit -m 'first commit'
git checkout -b feature-x
git add newFile.txt
git commit -m 'Added feature x'
git checkout master
git pull origin master
git merge feature-x
git push origin master

Resources

  • Books
    • Pro Git - Available free online
    • Pragmatic Guide to Git - Local author @tswicegood
    • Version Control with Git
  • Man pages
    git help <command>

MISC

Questions?

Brandon Williams
@rocketeerbkw
rocketeerbkw@gmail.com
rocketeerbkw.com