• Git Presentation

    Wo(r)k session : 17/01/2017

    Gipsa-Lab

  • How do you save your code ?

    • Store every working version in a separate folder
    • Take a huge amount of memory
  • What about working with your colleague on the same code ?

    • Share version on mobile storage unit (usb, HDD,… floppy disk ^^ )
    • File Comparison done by hand
    • Risk of erasure
    • Fusion is difficult
    • Loss of productivity
  • What about data restoration?

    • Recover from a code error
    • Code that no longer compiles
    • Maintains “release” and “debug” versions
  • Those questions will try to be resolved by the presentation of Git

  • Git’s history

  • Git’s architecture

  • How it work ?

  • Good practices

  • Extra

  • Linus torwals Talk about git :

    https://www.youtube.com/watch?v=4XpnKHJAok8

    Online interactive tutorial ( must try):

    https://try.github.io/

    Interactive tutorial for branching :

    http://learngitbranching.js.org/

    Git official website : https://git-scm.com/
    Documentation on bitbucket : https://www.atlassian.com/git/tutorials/install-git/
  • -Linus Torvalds

  • -Tux, Linux

  • Git :

    OpenSouce VCS (version control system) developed by Linus Torvalds for the linux kernel

    Linux kernel :

    • ~150Mo of source code(2010)
    • Thousands of developpers around the world
    • Need “stable release” alongside “development release”

    Nowadays :

    • Most popular VCS (used by >12 millions people)
    • Huge impact in the openSource community, academical, or in company.
  • Version control systems (VCS) :

    Software that allows to store a set of files while preserving the chronology of all the modifications that have been made on them.

  • Use of a versionning server:

    Initial goal: Keep track of all the modifications that happened on a source code during software development

    Extended goal: Keep track of every modification done onto textual documents (Report, Research paper, presentation, etc.).

    Wikis (like Wikipedia) also use these versionning management mechanisms on database fields intead on files.

    Mains currents VCS :

    SVN / GIT / Mercurial

    These three VCS woek as a client-server application running on a local or remote station. This is called a versionning server.

  • Git is decentralized

    Works in a decentralized way (unlike SVN) so that each locally hosts a local repository and shares a remote repository(public repository).

    This decentralization makes it possible to be resistant to hardware and software failures .

    Git allow everyone to work at their own pace, out of sync of a remote repository, while offering a way to developers to exchange their respective jobs and collaborates in a seamless way.

    The code history is present on each machine and is updated in an asynchronous way when the user submits a change ( commit ).

  • Local and remote repository

  • Branching

  • Installation

    Configurating users :

    $ git config —global user.name “Jean dupont”

    $ git config —global user.email “j.dupont@him.com”

  • Initialisation of the Git repertoire

    • git init = creation d’un repertoire
    • git clone ssh://john@example.com/path/to/my-project.git

    git clone https://github.com/impress/impress.js

  • Local commands

  • Remote commands

    (if remote repository)

  • The branches:

    - Git autorise les branches

  • Commands summary

  • Bidirectional compatibility between git and SVN

    • SVN -> Git: super easy with git svn clone
    • Git -> SVN: more complex because git is more advanced than SVN
  • Anecdote on the name

    Git =unpleasant person in British English slang

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

  • Before the Commit

    Add the files to the local staging area

    • git add my_file
    • git add -A : For all file
  • Commit :

    Move the elements from the staging area to the local repository

    • commit -m “my message about the commit”
  • Undoing Changes:

    Revert to a previous state (or commit)

    • git checkout id_commit : Move back to a previous commit state
    • git reset id_commit : Reset current branch to the specified state (clean staging area)
  • Temporary copy : stash

    Save the temporary state of the code.

    • git stash
    • git stash list
    • git stash apply / git stash pop
  • Init remote repository :

  • Push

    git push : push local repository to remote repository

  • Fetch & Pull

    • git fetch = download objects and refs from another repository
    • git pull = git fetch followed by a git merge
  • Create a branch:

    • git branch <ma_branche>
    • git branch List

    • Move to another branch :
      git checkout another_branch

  • Merge a branch

    • git checkout my_new_branch
    • git merge my_old_branch
{"cards":[{"_id":"74e6d0d76f0c9d67e4000066","treeId":"587b430618c57a4e7e0a3fcd","seq":9343211,"position":0.25,"parentId":null,"content":"# Git Presentation\n### Wo(r)k session : 17/01/2017\n### Gipsa-Lab"},{"_id":"74e62b6f07b59cbc6600005d","treeId":"587b430618c57a4e7e0a3fcd","seq":9342620,"position":0.28125,"parentId":null,"content":"# How do you save your code ?"},{"_id":"74e6d7f76f0c9d67e4000067","treeId":"587b430618c57a4e7e0a3fcd","seq":9342629,"position":0.296875,"parentId":null,"content":"* Store every working version in a separate folder\n* Take a *huge* amount of memory"},{"_id":"74e6313007b59cbc6600005e","treeId":"587b430618c57a4e7e0a3fcd","seq":9342636,"position":0.3125,"parentId":null,"content":"# What about working with your colleague on the same code ?"},{"_id":"74e6dacf6f0c9d67e4000068","treeId":"587b430618c57a4e7e0a3fcd","seq":9342648,"position":0.359375,"parentId":null,"content":"* Share version on mobile storage unit (usb, HDD,... floppy disk ^^ )\n* File Comparison done by hand\n* Risk of erasure\n* Fusion is difficult\n* Loss of productivity"},{"_id":"74d0a282f75887b7cb0000dc","treeId":"587b430618c57a4e7e0a3fcd","seq":9342651,"position":0.40625,"parentId":null,"content":"# What about data restoration?"},{"_id":"74e6db556f0c9d67e4000069","treeId":"587b430618c57a4e7e0a3fcd","seq":9343191,"position":0.453125,"parentId":null,"content":"* Recover from a code error\n* Code that no longer compiles\n* Maintains \"release\" and \"debug\" versions"},{"_id":"74e6db9a6f0c9d67e400006a","treeId":"587b430618c57a4e7e0a3fcd","seq":9343298,"position":0.4765625,"parentId":null,"content":"Those questions will try to be resolved by the presentation of * **`Git`** *"},{"_id":"587b430618c57a4e7e0a3fce","treeId":"587b430618c57a4e7e0a3fcd","seq":9343295,"position":1,"parentId":null,"content":"# Git's history"},{"_id":"74e7070c6f0c9d67e400006d","treeId":"587b430618c57a4e7e0a3fcd","seq":9347244,"position":2.15625,"parentId":"587b430618c57a4e7e0a3fce","content":"![](https://s23.postimg.org/3rkjk1ip7/AVT_Linus_Torvald_1898.jpg)-Linus Torvalds"},{"_id":"74e6eae66f0c9d67e400006c","treeId":"587b430618c57a4e7e0a3fcd","seq":9347246,"position":2.1875,"parentId":"587b430618c57a4e7e0a3fce","content":"![](https://s28.postimg.org/welkvwfyl/Tux.png)-Tux, Linux"},{"_id":"74d0eeeaf75887b7cb0000df","treeId":"587b430618c57a4e7e0a3fcd","seq":9342718,"position":2.25,"parentId":"587b430618c57a4e7e0a3fce","content":"#### **Git :**\n\nOpenSouce VCS (version control system) developed by Linus Torvalds for the linux kernel\n\n#### **Linux kernel :**\n\n* ~150Mo of source code(2010)\n* Thousands of developpers around the world\n* Need \"stable release\" alongside \"development release\"\n\n#### **Nowadays :**\n\n* Most popular VCS (used by >12 millions people)\n* Huge impact in the openSource community, academical, or in company.\n\n"},{"_id":"74e6bb426f0c9d67e4000060","treeId":"587b430618c57a4e7e0a3fcd","seq":9344468,"position":2.5,"parentId":"587b430618c57a4e7e0a3fce","content":"# Version control systems (VCS) :\n\nSoftware that allows to store a set of files while preserving the chronology of all the modifications that have been made on them."},{"_id":"74d0c087f75887b7cb0000de","treeId":"587b430618c57a4e7e0a3fcd","seq":9347873,"position":3,"parentId":"587b430618c57a4e7e0a3fce","content":"# Use of a versionning server:\n\n**Initial goal:** Keep track of all the modifications that happened on a source code during software development\n\n**Extended goal:** Keep track of every modification done onto textual documents (Report, Research paper, presentation, etc.).\n\nWikis (like Wikipedia) also use these versionning management mechanisms on database fields intead on files.\n\n\n# Mains currents VCS :\n**SVN / GIT / Mercurial** \n\nThese three VCS woek as a client-server application running on a local or remote station. This is called a versionning server.\n\n\n"},{"_id":"74d0a1e1f75887b7cb0000db","treeId":"587b430618c57a4e7e0a3fcd","seq":9343207,"position":2,"parentId":null,"content":"# Git's architecture"},{"_id":"74d11554f75887b7cb0000e0","treeId":"587b430618c57a4e7e0a3fcd","seq":9348247,"position":1,"parentId":"74d0a1e1f75887b7cb0000db","content":"\n## Git is decentralized\n\nWorks in a decentralized way (unlike SVN) so that each locally hosts a local repository and shares a remote repository(public repository).\n\nThis decentralization ** makes it possible to be resistant to hardware and software failures **.\n\nGit allow everyone to work at their own pace, out of sync of a remote repository, while offering a way to developers to exchange their respective jobs and collaborates in a seamless way. \n\nThe code history is present on each machine and is updated in an asynchronous way when the user submits a change (* commit *).\n\n![](https://s28.postimg.org/pa6ssfsgt/git_vs_svn.png)\n\n![](https://www.atlassian.com/git/images/tutorials/getting-started/why-git/03.svg)"},{"_id":"74e6c8266f0c9d67e4000063","treeId":"587b430618c57a4e7e0a3fcd","seq":9348254,"position":2,"parentId":"74d0a1e1f75887b7cb0000db","content":"## Local and remote repository\n\n![](https://s23.postimg.org/fjtyhqcl7/git_everthing_is_local.png)\n"},{"_id":"74e6c86d6f0c9d67e4000064","treeId":"587b430618c57a4e7e0a3fcd","seq":9348255,"position":3,"parentId":"74d0a1e1f75887b7cb0000db","content":"## Branching\n\n![](https://www.atlassian.com/git/images/tutorials/collaborating/using-branches/hero.svg)"},{"_id":"74d16713f75887b7cb0000e2","treeId":"587b430618c57a4e7e0a3fcd","seq":9342731,"position":3,"parentId":null,"content":"# How it work ?"},{"_id":"74d204faf75887b7cb000306","treeId":"587b430618c57a4e7e0a3fcd","seq":9348257,"position":1,"parentId":"74d16713f75887b7cb0000e2","content":"# Installation\n\n* **WINDOWS**\ninstaller : https://git-for-windows.github.io/\n\n* **Linux**\n\n $ sudo apt-get update\n\n $ sudo apt-get install git\n\n# Configurating users :\n\n $ git config --global user.name \"Jean dupont\"\n\n $ git config --global user.email \"j.dupont@him.com\"\n\n"},{"_id":"74d20691f75887b7cb000307","treeId":"587b430618c57a4e7e0a3fcd","seq":9347957,"position":2,"parentId":"74d16713f75887b7cb0000e2","content":"# Initialisation of the Git repertoire\n* *git init* = creation d'un repertoire\n* *git clone ssh://john@example.com/path/to/my-project.git*\n\ngit clone https://github.com/impress/impress.js\n\n "},{"_id":"74e577bef19b288b7000005e","treeId":"587b430618c57a4e7e0a3fcd","seq":9347961,"position":2.5,"parentId":"74d16713f75887b7cb0000e2","content":"# Local commands"},{"_id":"74d207a2f75887b7cb000308","treeId":"587b430618c57a4e7e0a3fcd","seq":9348264,"position":2,"parentId":"74e577bef19b288b7000005e","content":"### Before the *Commit*\nAdd the files to the local staging area \n* *git add my_file*\n* *git add -A* : For all file"},{"_id":"74d209cff75887b7cb000309","treeId":"587b430618c57a4e7e0a3fcd","seq":9348269,"position":3,"parentId":"74e577bef19b288b7000005e","content":"### *Commit* : \nMove the elements from the staging area to the local repository\n\n* *commit -m \"my message about the commit\"*"},{"_id":"74e57b86f19b288b70000061","treeId":"587b430618c57a4e7e0a3fcd","seq":9348303,"position":4,"parentId":"74e577bef19b288b7000005e","content":"### Undoing Changes:\nRevert to a previous state (or commit)\n\n* *git checkout id_commit* : Move back to a previous commit state\n* *git reset id_commit* : Reset current branch to the specified state (clean staging area)\n"},{"_id":"74e57cc1f19b288b70000062","treeId":"587b430618c57a4e7e0a3fcd","seq":9348311,"position":5,"parentId":"74e577bef19b288b7000005e","content":"### Temporary copy : *stash*\nSave the temporary state of the code.\n\n* *git stash*\n* *git stash list*\n* *git stash apply* / *git stash pop*"},{"_id":"74e578bbf19b288b70000060","treeId":"587b430618c57a4e7e0a3fcd","seq":9347963,"position":2.75,"parentId":"74d16713f75887b7cb0000e2","content":"# Remote commands\n\n(if remote repository)"},{"_id":"74e67dc507b59cbc66000062","treeId":"587b430618c57a4e7e0a3fcd","seq":9348633,"position":0.5,"parentId":"74e578bbf19b288b70000060","content":"### Init remote repository :\n\n* Copy of an existing repertoire : \n*git clone ssh://john@example.com/path/to/my-project.git *\n\n* *git remote add origin https://github.com/user/repo.git*\n"},{"_id":"74e5582ff19b288b70000059","treeId":"587b430618c57a4e7e0a3fcd","seq":9342688,"position":1,"parentId":"74e578bbf19b288b70000060","content":"### *Push*\n*git push* : push *local repository* to *remote repository*"},{"_id":"74e55ab8f19b288b7000005a","treeId":"587b430618c57a4e7e0a3fcd","seq":9348645,"position":2,"parentId":"74e578bbf19b288b70000060","content":"### *Fetch* & *Pull*\n* *git fetch* = download objects and refs from another repository\n* *git pull* = *git fetch* followed by a *git merge*"},{"_id":"74e55c6cf19b288b7000005c","treeId":"587b430618c57a4e7e0a3fcd","seq":9347977,"position":4.9375,"parentId":"74d16713f75887b7cb0000e2","content":"# The branches:\n\n![](https://www.atlassian.com/git/images/tutorials/collaborating/using-branches/01.svg) - Git autorise les branches\n"},{"_id":"74e6232907b59cbc6600005b","treeId":"587b430618c57a4e7e0a3fcd","seq":9348653,"position":3,"parentId":"74e55c6cf19b288b7000005c","content":"### Create a branch:\n\n![](https://www.atlassian.com/git/images/tutorials/collaborating/using-branches/04.svg)\n\n* *git branch <ma_branche>*\n* *git branch List*\n\n* Move to another branch : \n*git checkout another_branch*"},{"_id":"74e623a207b59cbc6600005c","treeId":"587b430618c57a4e7e0a3fcd","seq":9348664,"position":4,"parentId":"74e55c6cf19b288b7000005c","content":"### Merge a branch\n\n![](https://www.atlassian.com/git/images/tutorials/collaborating/using-branches/08.svg)\n\n* *git checkout my_new_branch*\n* *git merge my_old_branch*"},{"_id":"74e56d2ef19b288b7000005d","treeId":"587b430618c57a4e7e0a3fcd","seq":9347992,"position":4.96875,"parentId":"74d16713f75887b7cb0000e2","content":"# Commands summary\n\n![](https://s23.postimg.org/fjtyhqcl7/git_everthing_is_local.png)"},{"_id":"74e5e92984793ac926000059","treeId":"587b430618c57a4e7e0a3fcd","seq":9342738,"position":3.75,"parentId":null,"content":"# Good practices"},{"_id":"74e5e9df84793ac92600005a","treeId":"587b430618c57a4e7e0a3fcd","seq":9348172,"position":1,"parentId":"74e5e92984793ac926000059","content":"# Only follow text file\n* No binary (* .exe) or compiled files (* .pdf)\n* Each of the compiled files is duplicated in the memory"},{"_id":"74e610b907b59cbc66000059","treeId":"587b430618c57a4e7e0a3fcd","seq":9348186,"position":2,"parentId":"74e5e92984793ac926000059","content":"# Use of *.gitignore*\n\nGit will ignore the files in .gitignore file and don't them during the * git add ... *\n\nhttps://www.gitignore.io/"},{"_id":"74e63d5507b59cbc6600005f","treeId":"587b430618c57a4e7e0a3fcd","seq":9348242,"position":2.5,"parentId":"74e5e92984793ac926000059","content":"# !!! Where to store your data:\n\nOnline repository (*remote repository*) :\n* https://github.com/ (public repository if free account)\n* https://bitbucket.org/\n(private repository but limited)\n\n**`Warning: Us server, so US laws`**\n\n# Intellectual property\n\n* Git and SVN Server at Gipsa: see the info service\n\n* Self-hosting its own git server : https://gitlab.com\n\n\n\n"},{"_id":"74e64a7707b59cbc66000060","treeId":"587b430618c57a4e7e0a3fcd","seq":9348243,"position":2.75,"parentId":"74e5e92984793ac926000059","content":"# No personal data in the repository:\n\n`As the code that can be public and shared, do not put keys, login, and sensitive data in it.`\n\n* trufflehog :\nhttp://hackaday.com/2017/01/13/trufflehog-sniffs-github-for-secret-keys/\n\n* AWS key in the repository\nhttp://www.theregister.co.uk/2015/01/06/dev_blunder_shows_github_crawling_with_keyslurping_bots/"},{"_id":"74e6148e07b59cbc6600005a","treeId":"587b430618c57a4e7e0a3fcd","seq":9348244,"position":3,"parentId":"74e5e92984793ac926000059","content":"# Graphical Git client\nFor the one that are afraid by command line\n\n* Liste : https://git-scm.com/downloads/guis\n* SourceTree : https://www.sourcetreeapp.com/\n* SmartGit : https://www.syntevo.com/smartgit/"},{"_id":"74d1bf28f75887b7cb0000e5","treeId":"587b430618c57a4e7e0a3fcd","seq":9343288,"position":3.875,"parentId":null,"content":"# Extra"},{"_id":"74e5902284793ac926000057","treeId":"587b430618c57a4e7e0a3fcd","seq":9343289,"position":1,"parentId":"74d1bf28f75887b7cb0000e5","content":"### Bidirectional compatibility between git and SVN\n\n* **SVN -> Git**: super easy with * git svn clone *\n* **Git -> SVN**: more complex because git is more advanced than SVN"},{"_id":"74d1bfe2f75887b7cb0000e6","treeId":"587b430618c57a4e7e0a3fcd","seq":9343291,"position":2,"parentId":"74d1bf28f75887b7cb0000e5","content":"### Anecdote on the name\n*Git* =unpleasant person in British English slang\n\nLinus quoted : \"I'm an egotistical bastard, and I name all my projects after myself. First 'Linux', now 'git'.\""},{"_id":"74d168b9f75887b7cb0000e4","treeId":"587b430618c57a4e7e0a3fcd","seq":9343259,"position":3.9375,"parentId":null,"content":"### External resources / links\n\n###### Linus torwals Talk about git :\nhttps://www.youtube.com/watch?v=4XpnKHJAok8\n\n###### Online interactive tutorial ( must try):\nhttps://try.github.io/\n\n###### Interactive tutorial for branching :\nhttp://learngitbranching.js.org/\n\n###### Git official website : https://git-scm.com/\n\n###### Documentation on bitbucket : https://www.atlassian.com/git/tutorials/install-git/"},{"_id":"74e768e66f0c9d67e4000298","treeId":"587b430618c57a4e7e0a3fcd","seq":9348670,"position":5,"parentId":null,"content":"![](http://catplanet.org/wp-content/uploads/2014/10/Thanks-for-your-attention.jpg)"}],"tree":{"_id":"587b430618c57a4e7e0a3fcd","name":"Presentation Git","publicUrl":"presentation-git"}}