GIT

Coucou, tu veux voir mon git ?

Ingrid, est-ce que tu rebase ?

LINUS TORVALD

“I’m an egotistical bastard, and I name all my projects after myself. First Linux, now git.” – Linus

Created in 2005

Maintained by
Junio Hamano
since July 2005

GIT != Subversion + magic

Git is a stupid content tracker.

not a delta or diff

only you data

Git Object Types

Everything works thank to

THE SHA-1

257cc5642cb1a054f08cc83f2d943e56fd3ebe99

Everything works thank to

THE SHA-1

257cc5642cb1a054f08cc83f2d943e56fd3ebe99

Everything works thank to

THE SHA-1

257cc5642cb1a054f08cc83f2d943e56fd3ebe99

Everything works thank to

THE SHA-1

--- .git
|      |--- objects

|      |      |--- 25
|      |      |      |--- 7cc5642cb1a054f08cc83f2d943e56fd3ebe99

The Blob

 The contents of your files

The Tree

Your directories

The Commit

 The 'history' part of 'tree history storage system'

The Tag

 Permanent shorthand name for a particular commit

Git is
a directed acyclic graph

Over the time

Over the time

Over the time

Over the time

Over the time

A demo is worth a thousand of words

GIT operations

Branching

It's creating a file that has the SHA-1 of the last commit

Merging

It's moving the HEAD pointer of a branch to the latest SHA-1 commit of another branch

If there is changes on both sides, a commit with multiple parent will be created

Beware of Chaos Merging

Rebase is the solution

Rebase is the solution

Speak treeish

Speak treeish

Full sha-1
        dae86e1950b1277e545cee180551750029cfe735

Partial sha-1
        dae86e1

Branch or Tag name
        master

Date spec
        master@{yesterday}
        master@{1 month ago}

Based on .git/logs files

Speak treeish

Ordinal spec
        master@{5}

Carrot parent
        e65s46^2

        master^5

Based on .git/logs files

Based on .git/logs files

Tilde spec
        e65s46~5

equals to   e65s46^^^^^

Speak treeish

Carrot parent
        e65s46^2

        master^5

Tilde spec
        e65s46~5

Configure your git

Configure git

$ git config --global user.name "Nom et Prénom"			
$ git config --global user.email mail@domaine.tld			
$ git config --global core.autocrlf input			

Configure git

[core]
 repositoryformatversion = 0
 filemode = true
 bare = false
 logallrefupdates = true

[remote "origin"]
 url = git@github.com:username/myproject.git
 fetch = +refs/heads/*:refs/remotes/origin/*

[branch "master"]
 remote = origin
 merge = refs/heads/master

Configure git

[core]
 repositoryformatversion = 0
 filemode = true
 bare = false
 logallrefupdates = true

[remote "upstream"]
 url = git@github.com:projectowner/project.git
 fetch = +refs/heads/*:refs/remotes/upstream/*

[remote "origin"]
 url = git@github.com:yourfork/project.git
 fetch = +refs/heads/*:refs/remotes/origin/*

[branch "master"]
 remote = origin
 merge = refs/heads/master

Greet the flow !

Bonnes pratiques

Bonnes pratiques

  • Utiliser SSH plutôt que HTTP

Bonnes pratiques

  • Utiliser SSH plutôt que HTTP
  • Signer ses commits à l'aide d'une clé GPG

Bonnes pratiques

  • Utiliser SSH plutôt que HTTP
  • Signer ses commits à l'aide d'une clé GPG
  • Toujours travailler sur une branche

Bonnes pratiques

  • Utiliser SSH plutôt que HTTP
  • Signer ses commits à l'aide d'une clé GPG
  • Toujours travailler sur une branche
  • Après une revue de code, que des nouveaux commits

Bonnes pratiques

  • Utiliser SSH plutôt que HTTP
  • Signer ses commits à l'aide d'une clé GPG
  • Toujours travailler sur une branche
  • Après une revue de code, que des nouveaux commits
  • Avant un merge, mettre à jour sa branche avec pull --rebase=preserve

Bonnes pratiques

  • Utiliser SSH plutôt que HTTP
  • Signer ses commits à l'aide d'une clé GPG
  • Toujours travailler sur une branche
  • Après une revue de code, que des nouveaux commits
  • Avant un merge, mettre à jour sa branche avec pull --rebase=preserve
  • Avant un merge,  rebase -i pour obtenir une séparation atomique logique des commits  en squashant les commits non pertinents

Bonnes pratiques

  • Utiliser SSH plutôt que HTTP
  • Signer ses commits à l'aide d'une clé GPG
  • Toujours travailler sur une branche
  • Après une revue de code, que des nouveaux commits
  • Avant un merge, mettre à jour sa branche avec pull --rebase=preserve
  • Avant un merge,  rebase -i pour obtenir une séparation atomique logique des commits  en squashant les commits non pertinents
  • Utiliser git flow

Bonnes pratiques

  • Utiliser SSH plutôt que HTTP
  • Signer ses commits à l'aide d'une clé GPG
  • Toujours travailler sur une branche
  • Après une revue de code, que des nouveaux commits
  • Avant un merge, mettre à jour sa branche avec pull --rebase=preserve
  • Avant un merge,  rebase -i pour obtenir une séparation atomique logique des commits  en squashant les commits non pertinents
  • Utiliser git flow
  • Normer la manière de commenter ses commit

Bonnes pratiques

  • Utiliser SSH plutôt que HTTP
  • Signer ses commits à l'aide d'une clé GPG
  • Toujours travailler sur une branche
  • Après une revue de code, que des nouveaux commits
  • Avant un merge, mettre à jour sa branche avec pull --rebase=preserve
  • Avant un merge,  rebase -i pour obtenir une séparation atomique logique des commits  en squashant les commits non pertinents
  • Utiliser git flow
  • Normer la manière de commenter ses commit
  • Pour les hotfix créer une branche qui sera mergé dans master et dev

Bonus

$ git cherry-pick dae86e1

Bonus

$ git cherry-pick dae86e1
$ git pull --rebase=preserve

Bonus

$ git cherry-pick dae86e1
$ git pull --rebase=preserve
git branch -r | awk "{print substr($1,8)}" | \
egrep -v -f /dev/fd/0 <(git branch) | \
awk "{print $1}" | xargs git branch -D

Bonus

[alias]
    # edit last commit
    amend = commit --amend -C HEAD

    # cancel last local commit
    undo = reset --soft HEAD^

    # rapid checkup
    changes = diff --name-status
    dic = diff --cached
    diffstat = diff --stat

    # condensed logs
    hist = log --pretty=oneline --abbrev-commit --graph --decorate
    lg = log --graph --pretty=tformat:\"%Cred%h%Creset -%C(cyan)%d %Creset%s %Cgreen(%an %cr)%Creset\" --abbrev-commit --date=relative
    st = status

    # show changes since last pull
    lc = !git log ORIG_HEAD.. --stat --no-merges

    # add modified files to commit
    addm = !git ls-files -m -z | xargs -0 git-add && git status
        
    # add new files to commit
    addu = !git ls-files -o --exclude-standard -z | xargs -0 git-add && git status
    
    # delete files marked as suppressed
    rmm = !git ls-files -d -z | xargs -0 git-rm && git status

    # open on textMate last uncommited files
    mate = !git ls-files -m -z | xargs -0 mate
    mateall = !git ls-files -m -o --exclude-standard -z | xargs -0 mate

    # open on vi last uncommited files
    vi = !vi $(git ls-files -m -z)
    viall = !vi $(git ls-files -m -o --exclude-standard -z)

    # show all users that did commit
    who = shortlog -sne
[alias]
    # edit last commit
    amend = commit --amend -C HEAD

    # cancel last local commit
    undo = reset --soft HEAD^

    # rapid checkup
    changes = diff --name-status
    dic = diff --cached
    diffstat = diff --stat

    # condensed logs
    hist = log --pretty=oneline --abbrev-commit --graph --decorate
    lg = log --graph --pretty=tformat:\"%Cred%h%Creset -%C(cyan)%d %Creset%s %Cgreen(%an %cr)%Creset\" --abbrev-commit --date=relative
    st = status

    # show changes since last pull
    lc = !git log ORIG_HEAD.. --stat --no-merges

    # add modified files to commit
    addm = !git ls-files -m -z | xargs -0 git-add && git status
        
    # add new files to commit
    addu = !git ls-files -o --exclude-standard -z | xargs -0 git-add && git status
    
    # delete files marked as suppressed
    rmm = !git ls-files -d -z | xargs -0 git-rm && git status

    # open on textMate last uncommited files
    mate = !git ls-files -m -z | xargs -0 mate
    mateall = !git ls-files -m -o --exclude-standard -z | xargs -0 mate

    # open on vi last uncommited files
    vi = !vi $(git ls-files -m -z)
    viall = !vi $(git ls-files -m -o --exclude-standard -z)

    # show all users that did commit
    who = shortlog -sne

Bonus

[alias]
    # edit last commit
    amend = commit --amend -C HEAD

    # cancel last local commit
    undo = reset --soft HEAD^

    # rapid checkup
    changes = diff --name-status
    dic = diff --cached
    diffstat = diff --stat

    # condensed logs
    hist = log --pretty=oneline --abbrev-commit --graph --decorate
    lg = log --graph --pretty=tformat:\"%Cred%h%Creset -%C(cyan)%d %Creset%s %Cgreen(%an %cr)%Creset\" --abbrev-commit --date=relative
    st = status

    # show changes since last pull
    lc = !git log ORIG_HEAD.. --stat --no-merges

    # add modified files to commit
    addm = !git ls-files -m -z | xargs -0 git-add && git status
        
    # add new files to commit
    addu = !git ls-files -o --exclude-standard -z | xargs -0 git-add && git status
    
    # delete files marked as suppressed
    rmm = !git ls-files -d -z | xargs -0 git-rm && git status

    # open on textMate last uncommited files
    mate = !git ls-files -m -z | xargs -0 mate
    mateall = !git ls-files -m -o --exclude-standard -z | xargs -0 mate

    # open on vi last uncommited files
    vi = !vi $(git ls-files -m -z)
    viall = !vi $(git ls-files -m -o --exclude-standard -z)

    # show all users that did commit
    who = shortlog -sne
[alias]
    # edit last commit
    amend = commit --amend -C HEAD

    # cancel last local commit
    undo = reset --soft HEAD^

    # rapid checkup
    changes = diff --name-status
    dic = diff --cached
    diffstat = diff --stat

    # condensed logs
    hist = log --pretty=oneline --abbrev-commit --graph --decorate
    lg = log --graph --pretty=tformat:\"%Cred%h%Creset -%C(cyan)%d %Creset%s %Cgreen(%an %cr)%Creset\" --abbrev-commit --date=relative
    st = status

    # show changes since last pull
    lc = !git log ORIG_HEAD.. --stat --no-merges

    # add modified files to commit
    addm = !git ls-files -m -z | xargs -0 git-add && git status
        
    # add new files to commit
    addu = !git ls-files -o --exclude-standard -z | xargs -0 git-add && git status
    
    # delete files marked as suppressed
    rmm = !git ls-files -d -z | xargs -0 git-rm && git status

    # open on textMate last uncommited files
    mate = !git ls-files -m -z | xargs -0 mate
    mateall = !git ls-files -m -o --exclude-standard -z | xargs -0 mate

    # open on vi last uncommited files
    vi = !vi $(git ls-files -m -z)
    viall = !vi $(git ls-files -m -o --exclude-standard -z)

    # show all users that did commit
    who = shortlog -sne

Merci !
Des questions ?

Bonus : cheat sheet

Voir nos autres formations sur : masterclass.les-tilleuls.coop

GIT

By Grégoire Hébert

GIT

No one should fear git

  • 613
Loading comments...

More from Grégoire Hébert