Created by Michael Noseworthy
git is a distributed revision control system created by Linus Torvalds in April 2005
For a long while, Linux kernel maintenance was done via tarball patches
Linus hated CVS and SVN and didn't see the point of either system
In the 1990's BitKeeper was discussed as a solution to the Linux teams source control problems
BitKeeper was one of the first distributed revision control systems, and the Linux kernel was it's highest profile Open Source project
BitKeeper was free for OSS as long as developers didn't work on competing systems
BitKeeper's CEO claimed that an OSS developer, Andrew Tridgell reverse-engineered the BitKeeper protocols and violated the license
After much drama, the Linux team stopped using BitKeeper
Linus evaluated Alternatives. They had to be:
Linus' requirements eliminated all existing systems
CVS and SVN met none of the requirements
All other distributed systems were either closed, behind a pay wall, or didn't meet the requirements
Linus went home for the weekend, and early next week released the first version of git on April 7, 2005
It took Linus about a day to get git "self hosting", i.e., able to commit changes to git using git*
Why call it git
British slang for "an unpleasant person"
"I'm an egotistical bastard, and I name all my projects after myself. First 'Linux', now 'git'."
Forget everything you know about CVS and SVN
Linus designed git to satisfy the requirements he outlined for a version control system that would be suitable to develop the linux kernel
Distributed, Fast, and Consistent
Every copy of the repository has a complete history
git keeps track of other repositories that you can "pull" from and/or "push" to. These are called remotes
Because of this distributed model, there were no politics around who could commit and when. Everyone could commit to the Linux kernel all the time. Even offline!
git's branching and merge strategy strongly supports non-linear development
git's intelligent merge strategies rarely result in users having to manually resolve
There are a number of factors that make git fast, mainly:
Each version of the repo is identified by a SHA-1 hash that depends on the complete history of the project
Using a cryptographically secure hash algorithm ensures that history can't be modified without git noticing
git ensures by design that you get back exactly what you committed every time
git is built as a toolkit of small c programs stitched together with scripts
First git commands are usually:
$ git config --global user.name "YOUR NAME"
$ git config --global user.email "YOUR EMAIL ADDRESS"
Creates a .git directory inside an existing directory
.git directories store all the configuration and history for the repo
Clone from github:
$ git clone git@github.com:hakimel/reveal.js.git
Create a branch:
$ git branch BRANCH_NAME
Delete a branch:
$ git branch -d BRANCH_NAME
Force delete a branch:
$ git branch -D BRANCH_NAME
List all branches:
$ git branch
Switch to a feature branch:
$ git checkout FEATURE_BRANCH_NAME
Switch back to master:
$ git checkout master
Discard unstaged changes:
$ git checkout -- path/to/file
Create new branch and switch to it:
$ git checkout -b NEW_BRANCH_NAME
Add a specific file:
$ git add path/to/file
Add everything:
$ git add .
Launch editor to write commit message and commit on save:
$ git commit
Add changes from any tracked files and commit:
$ git commit -a
Launch editor (displaying current diff) to write message and commit on save:
$ git commit -v
Commit with one-liner message:
$ git commit -m "Commit message!"
Fetch from remote origin:
$ git fetch origin
$ git status
Just show a history of commits on this branch:
$ git log
Show log by author:
$ git log --author=user@domain.com
Show log with ASCII art graph of branching
$ git log --graph
Merge changes from a feature branch:
$ git merge FEATURE_BRANCH_NAME
Pull changes from a remote master branch at the origin:
$ git pull origin master
Push a feature branch to the origin:
$ git push origin FEATURE_BRANCH
You can set other remotes to push to and pull from, but that is outside the scope of this talk and not very common outside of OSS
Much to Linus' chagrin, most people find value in using an "official" hosted repository, but the most common workflows aren't too different from his ideal
|
Github |
BitBucket
|
|
Centralized Workflow |
Forking Workflow |
Similar to the workflow of CVS or SVN
Everyone on the team has read and write access to the official hosted repository
A branching strategy is usually employed and team members open pull requests against the master branch
Most similar to Linus' ideal distributed workflow
Project owner/maintainer(s) manage the official repo
Team members fork the official repo and have their own hosted versions that they develop on
When team members want changes to make it in to the official repository, they open a pull request against the official repository
The maintainer(s) will review and merge the branch or reject it
Three branches: master, test, dev
As was said before, git's branches are super lightweight
A branch is just a pointer to a commit
Create branches off of the dev branch to do edits and merge feature branches back into dev
This is a fantastic git resource. In depth, easy to read tutorials on all the major features of git
Out of Scope for this talk
I don't like them. Though I understand that sometimes they can make repo organization easier (though they usually end up making it worse)
Here's a link to the submodule chapter of Pro Git for you to read later