Rebase, you git !

Presenter Notes

whoami

  • Haïkel Guémar
  • Fedora Packager
  • Senior Engineer @ SysFera
  • twitter: @hguemar

Presenter Notes

Plan

  • Background
  • Under the hood
  • Workflows
  • Use
  • GitHub
  • The End Of Hypnosis

Presenter Notes

* from Geek Hero Comic CC-By-NC-SA 3.0

Presenter Notes

Background

Presenter Notes

Version Control

  • manages and tracks different version of content
  • allow collaborative work

Presenter Notes

Some history

  • 1972: SCSS
  • 1982: RCS
  • 1986: CVS
  • 2001: BitKeeper, GNU Arch
  • 2002: SVN, Darcs
  • 2003: Monotone
  • 2005: Git, Mercurial
  • 2007: Bazaar

Presenter Notes

Daddy

Linus Torvalds, Linux Kernel Creator

Presenter Notes

The name

I'm an egotistical bastard, and I name all my projects after myself. First 'Linux', now 'git'.

Presenter Notes

A bit of history

  • April, 3rd 2005: beginning of development
  • April, 6th 2005: first release
  • April, 7th 2005: git development is self-hosted
  • July, 26th 2005: Junio Hamano is appointed as the new maintainer

Presenter Notes

Junio Hamano

Presenter Notes

Why ?

  • Linux kernel hackers BitKeeper licenses were revoked
  • No FLOSS alternatives in many aspects

Presenter Notes

Design

  • CVS: "There is no way to make CVS right"
  • Facilitates (highly) distributed workflow that scales
  • Maintains data integrity
  • Performant enough for kernel development
  • Design inspired by File Systems

Presenter Notes

What does Git bring you ?

A SCM that is

  • distributed
  • performant
  • no forced workflow (Bring Your Own Workflow)
  • robust
  • cheap branches
  • history rewrite
  • offline work

Presenter Notes

Under the hood

Presenter Notes

Git is

a content manager

stored as an objects acyclic graph

objects accessible through references

Presenter Notes

A layered tool

  • porcelain (frontend)
  • plumbing (backend)

Presenter Notes

In the beginning

There were only plumbing commmands

Many frontends were made available (cogito, eg)

Presenter Notes

Understanding git internals is the key for efficient use

Presenter Notes

Information Manager from hell

Remember that git is a content manager

Presenter Notes

Repository

Is a

  • database that contain a project whole history
  • complete copy of a project

Built upon two data structures

  • object store
  • index

Presenter Notes

SHA-1

Every object is identified by a SHA-1

Which garantees unicity up to 2^160 objects

Presenter Notes

Objects

  • blobs
  • trees
  • commits
  • tags

Presenter Notes

Index

Also know as staging area

Presenter Notes

Let's link everything together

Presenter Notes

Presenter Notes

Presenter Notes

Two kinds of references

  • Managed by git
  • Managed by users

Presenter Notes

Instance of references managed by git

Presenter Notes

Instance of references managed by git

Presenter Notes

Instance of references managed by git

Presenter Notes

And branches ?

They're just references too, that's why you get cheap branching !

Presenter Notes

Users managed references

tags !

Presenter Notes

In the end

  • No time based vision
  • Commits are linked to each other in a graph
  • Objects are immutable
  • but the graph itself is mutable
  • Content is accessed through references

Presenter Notes

Bring Your Own Workflow

  • No forced workflow
  • Forks are encouraged

Presenter Notes

Forks encouraged ?

Presenter Notes

A game changer

  • No more commit access rights
  • Disagree ? Just fork it !

No more assymetry between maintainer(s) and the others

Presenter Notes

Some examples of workflows


Presenter Notes

Centralized

centralized

Presenter Notes

Intégration

integration manager

Presenter Notes

Linux

Linus

Presenter Notes

gitflow

Presenter Notes

Use

Presenter Notes

145 commands / 76 porcelains

37 main

14 manipulations

16 interrogations

9 interactions

Presenter Notes

Essentials

init/merge/clone

fetch/commit/push/branch

checkout/add/log/diff

Presenter Notes

Configure your environment

git config --global user.name "John Doe"
git config --global user.email john@doe.com

Presenter Notes

gitignore

Tell git to ignore files:

  • by repository: using local .gitignore file
  • globally:

    !bash git config --global core.excludesfile ~/.gitignore

Presenter Notes

gitignore

# Compiled source
*.o
*.so
# python
__pycache__
*.py[cdo]
# editors stuff
*~
.\#*

Samples provided by github community

Presenter Notes

Aliases

git config --global alias.st "status -sb"

Presenter Notes

Some useful aliases

st    = status -sb
ci    = commit
co    = checkout
br    = branch -a
rb    = rebase
sb    = show-branch
unadd = rm -r --cached
wd    = diff --word-diff
ws    = show --word-diff
purr  = pull --rebase
amend = commit --amend

Presenter Notes

Moving between references

ref^ = ref parent
ref~2 = ref grand-parent

Presenter Notes

Presenter Notes

master^

Presenter Notes

master^2

Presenter Notes

master^

Presenter Notes

Learn fishing

git help -w gittutorial

Presenter Notes

Create/clone a repository

git init <green-field-project>
git clone --bare <green-field-project>> # gives you <green-field-project.git>
git clone <uri-repository>

Presenter Notes

Manage remotes

 git remote add backup <uri>
 git remote set-url backup <new-uri>

Presenter Notes

Push it

git fetch
git pull # git fetch; git merge
git pull --rebase # git fetch; git rebase
git push

Presenter Notes

Branching

Presenter Notes

Branches

git branch foo
git branch -m
git branch -D bar
git push origin foo
git push --set-upstream origin foo:baz
git push origin :origin/foo

Presenter Notes

Branches

git checkout myfeature # origin/myfeature exists
git checkout -b myfeature-local --track origin/myfeature

Presenter Notes

Moving around

Presenter Notes

Moving around

Presenter Notes

Moving around

$ git branch 
* default
experiment

Presenter Notes

Moving around

Presenter Notes

Moving around

$ git branch 
  default
* experiment

Presenter Notes

Build progressively your commits

Presenter Notes

Build progressively your commits

Presenter Notes

Build progressively your commits

git add -p

Presenter Notes

Check your changes

Presenter Notes

Check your changes

Presenter Notes

The treasure island !

git stash

Presenter Notes

Modify last commit

git commit --amend

Presenter Notes

A big mistake ?

git reflog

Presenter Notes

Let's talk about serious matters

Presenter Notes

Merge

Presenter Notes

Merge

Presenter Notes

Let's do better ...

... and make it simpler with rebasing !

Presenter Notes

Rebase

Presenter Notes

Rebase

git rebase master

Presenter Notes

We can do better ...

... let's rewrite history

Presenter Notes

A dangerous git revisionnist in action !

Presenter Notes

Yummy, cherries !

Presenter Notes

Yummy, cherries !

git cherry-pick C9

Presenter Notes

Yummy, cherries !

Presenter Notes

Yummy, cherries !

Presenter Notes

Yummy, cherries !

Presenter Notes

rebase --interactive

Presenter Notes

rebase --interactive

Presenter Notes

rebase --interactive

Presenter Notes

rebase --interactive

Presenter Notes

rebase --interactive

Presenter Notes

rebase --interactive

Presenter Notes

rebase --interactive

allows you to:

  • edit commits
  • merge/slice commits
  • remove commits
  • reorder commits

Presenter Notes

GitHub

Presenter Notes

GitHub

Social Coding Platform

Presenter Notes

Model

  • Fork & Pull Request
  • Encourage collaborative work through gamification

Presenter Notes

Pull Requests

  • Ding Dong, I have commits to share with you
  • discussion around your modification
  • merge (or get rejected)

Presenter Notes

Example

https://github.com/blog/1124-how-we-use-pull-requests-to-build-github

Presenter Notes

Presenter Notes

Code review

  • Improve drastically code quality
  • Lower defect rates
  • Encourage communication
  • Sets a common ground for the team (coding standards, architecture, etc.)

Presenter Notes

Clean code depends on YOU

Presenter Notes

Some resources

  • Official site: http://git-scm.com/
  • Pro-Git: http://git-scm.com/book/
  • O'Reilly: "Version Control with Git"

Presenter Notes

That's all folks !

Presenter Notes

Q/A

Presenter Notes