Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Git

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest. →

 Git

Slides from a Git introduction lecture at ENSAE for second-year students. Slides are in French but there isn’t much text.

Note this is here for archive only. I don’t think anymore that this is the right way to teach Git.

Baptiste Fontaine

November 14, 2016

Transcript

223 slides
  1. 1.

  2. 3.

  3. > git init Initialized empty Git repository in /…/monProjet/.git/ >

    git status On branch master Initial commit nothing to commit (create/copy files and use "git add" to track)
  4. > git init Initialized empty Git repository in /…/monProjet/.git/ >

    git status On branch master Initial commit nothing to commit (create/copy files and use "git add" to track)
  5. > git help <command> > git help add > git

    help status > git help init > git help log
  6. > git status On branch master Initial commit Untracked files:

    (use "git add <file>..." to include in what will be committed) README.txt main.cpp nothing added to commit but untracked files present (use "git add" to track)
  7. > git status On branch master Initial commit Untracked files:

    (use "git add <file>..." to include in what will be committed) README.txt main.cpp nothing added to commit but untracked files present (use "git add" to track) {
  8. > git status --short A main.cpp ?? README.txt > git

    status --short ?? README.txt ?? main.cpp > git add main.cpp
  9. > git status --short A main.cpp A README.txt > git

    status --short ?? README.txt ?? main.cpp > git add .
  10. > git status --short A main.cpp A README.txt > git

    status --short ?? README.txt ?? main.cpp > git add *
  11. > git status --short A main.cpp A README.txt > git

    add . > git reset main.cpp > git status --short ?? main.cpp A README.txt
  12. > git status --short A main.cpp A README.txt > git

    commit -m \ "initial commit" [master (root-commit) dc3bcbe] initial commit 2 files changed, 11 insertions(+) create mode 100644 README.txt create mode 100644 main.cpp
  13. > git status --short > git status On branch master

    nothing to commit, working tree clean (rien)
  14. > git mv main.cpp a.cpp > git status --short R

    main.cpp -> a.cpp > git commit -m "move stuff" [master 50b4a18] move stuff 1 file changed, 0 insertions(+), 0 deletions(-) rename main.cpp => a.cpp (100%)
  15. > git rm a.cpp rm 'a.cpp' > git status --short

    D a.cpp > git commit -m "remove stuff" [master bf366d7] remove stuff 1 file changed, 7 deletions(-) delete mode 100644 a.cpp
  16. Recap git init git status (--short) git add <file> git

    commit -m "………" git reset -- <file>
  17. Recap git init git status (--short) git add <file> git

    commit -m "………" git mv <file1> <file2> git rm <file> git reset -- <file>
  18. log

  19. commit bf366d79d16245ce9d851465ee5fcb2847ad82fb Author: Baptiste Fontaine <[email protected]> Date: Sun Nov 13

    13:46:17 2016 +0100 remove stuff commit 50b4a18b336f154d04b37f07fc7b9f529a124fcc Author: Baptiste Fontaine <[email protected]> Date: Sun Nov 13 13:41:22 2016 +0100 move stuff commit dc3bcbe86f22be1029d70f3e0642c23084173b7e Author: Baptiste Fontaine <[email protected]> Date: Sun Nov 13 13:16:38 2016 +0100 initial commit > git log
  20. commit bf366d79d16245ce9d851465ee5fcb2847ad82fb Author: Baptiste Fontaine <[email protected]> Date: Sun Nov 13

    13:46:17 2016 +0100 remove stuff delete mode 100644 a.cpp commit 50b4a18b336f154d04b37f07fc7b9f529a124fcc Author: Baptiste Fontaine <[email protected]> Date: Sun Nov 13 13:41:22 2016 +0100 move stuff rename main.cpp => a.cpp (100%) commit dc3bcbe86f22be1029d70f3e0642c23084173b7e Author: Baptiste Fontaine <[email protected]> Date: Sun Nov 13 13:16:38 2016 +0100 initial commit create mode 100644 README.txt create mode 100644 main.cpp > git log --summary
  21. commit bf366d79d16245ce9d851465ee5fcb2847ad82fb Author: Baptiste Fontaine <[email protected]> Date: Sun Nov 13

    13:46:17 2016 +0100 remove stuff delete mode 100644 a.cpp commit 50b4a18b336f154d04b37f07fc7b9f529a124fcc Author: Baptiste Fontaine <[email protected]> Date: Sun Nov 13 13:41:22 2016 +0100 move stuff rename main.cpp => a.cpp (100%) commit dc3bcbe86f22be1029d70f3e0642c23084173b7e Author: Baptiste Fontaine <[email protected]> Date: Sun Nov 13 13:16:38 2016 +0100 initial commit create mode 100644 README.txt create mode 100644 main.cpp > git log --summary
  22. bf366d7 remove stuff delete mode 100644 a.cpp 50b4a18 move stuff

    rename main.cpp => a.cpp (100%) dc3bcbe initial commit create mode 100644 README.txt create mode 100644 main.cpp > git log --oneline --summary
  23. > vim hello.cpp > git add . > git commit

    -m "Add hello.cpp" [master f8f6ceb] Add hello.cpp 1 file changed, 7 insertions(+) create mode 100644 hello.cpp > vim Makefile > git commit -m "Add Makefile" [master 622f151] Add Makefile 1 file changed, 2 insertions(+) create mode 100644 Makefile > vim Makefile > git add . > git commit -m "Makefile: Add 'clean' target" [master e0b1888] Makefile: Add 'clean' target 1 file changed, 6 insertions(+), 1 deletion(-) > vim README.txt > git add . > git commit -m "README: Add compilation instructions" [master 1365375] README: Add compilation instructions 1 file changed, 5 insertions(+)
  24. > git log --oneline --summary 1365375 README: Add compilation instructions

    e0b1888 Makefile: Add 'clean' target 622f151 Add Makefile create mode 100644 Makefile f8f6ceb Add hello.cpp create mode 100644 hello.cpp bf366d7 remove stuff delete mode 100644 a.cpp 50b4a18 move stuff rename main.cpp => a.cpp (100%) dc3bcbe initial commit create mode 100644 README.txt create mode 100644 main.cpp
  25. > git log --oneline --summary 1365375 README: Add compilation instructions

    e0b1888 Makefile: Add 'clean' target 622f151 Add Makefile create mode 100644 Makefile f8f6ceb Add hello.cpp create mode 100644 hello.cpp bf366d7 remove stuff delete mode 100644 a.cpp 50b4a18 move stuff rename main.cpp => a.cpp (100%) dc3bcbe initial commit create mode 100644 README.txt create mode 100644 main.cpp
  26. > git show e0b1888 commit e0b188879ba1a5aab3c0a732d5188a84a338850a Author: Baptiste Fontaine <[email protected]>

    Date: Sun Nov 13 19:43:57 2016 +0100 Makefile: Add 'clean' target diff --git a/Makefile b/Makefile index 74759f0..3da0c15 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,7 @@ -hello: hello.cpp +TARGET=hello + +$(TARGET): hello.cpp }
  27. > git show --oneline e0b1888 e0b1888 Makefile: Add 'clean' target

    diff --git a/Makefile b/Makefile index 74759f0..3da0c15 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,7 @@ -hello: hello.cpp +TARGET=hello + +$(TARGET): hello.cpp g++ $< -o $@ + +clean: + rm -f $(TARGET)
  28. > git diff diff --git a/README.txt b/README.txt index 78c5cf8..033103a 100644

    --- a/README.txt +++ b/README.txt @@ -1,7 +1,7 @@ MyProject ========= -This is my project. +This is my awesome project. Compile -------
  29. > git diff --word-diff diff --git a/README.txt b/README.txt index 78c5cf8..033103a

    100644 --- a/README.txt +++ b/README.txt @@ -1,7 +1,7 @@ MyProject ========= This is my {+awesome+} project. Compile -------
  30. > git add . > git diff --staged diff --git

    a/README.txt b/README.txt index 78c5cf8..033103a 100644 --- a/README.txt +++ b/README.txt @@ -1,7 +1,7 @@ MyProject ========= -This is my project. +This is my awesome project. Compile -------
  31. > git clone https://github.com/bfontaine/example.git Cloning into 'example'... remote: Counting objects:

    19, done. remote: Compressing objects: 100% (16/16), done. remote: Total 19 (delta 0), reused 19 (delta 0), pack-reused 0 Unpacking objects: 100% (19/19), done.
  32. > git clone https://github.com/bfontaine/example.git Cloning into 'example'... remote: Counting objects:

    19, done. remote: Compressing objects: 100% (16/16), done. remote: Total 19 (delta 0), reused 19 (delta 0), pack-reused 0 Unpacking objects: 100% (19/19), done. > ls example/ Makefile README.txt hello.cpp
  33. > git remote add \ > git remote origin origin

    [email protected]:bfontaine/example.git > git remote -v origin [email protected]:bfontaine/example.git (fetch) origin [email protected]:bfontaine/example.git (push)
  34. > git {push pull }origin master > git push -u

    origin master Branch master set up to track remote branch master from origin.
  35. > git {push pull }origin master > git push -u

    origin master Branch master set up to track remote branch master from origin. > git push > git pull
  36. > git branch * master > git branch doc >

    git branch * master > git checkout doc Switched to branch 'doc' doc
  37. > git branch * master > git branch doc >

    git branch * master doc > git checkout doc Switched to branch 'doc' > git branch master * doc
  38. > git checkout -b doc > git branch * master

    Switched to a new branch 'doc' > git branch master * doc
  39. > git diff diff --git a/hello.cpp b/hello.cpp index 205ec4e..5aaf27d 100644

    --- a/hello.cpp +++ b/hello.cpp @@ -1,5 +1,6 @@ #include <iostream> +// This function is so useful int main() { std::cout << "Hello, World!" << std::endl;
  40. > git add . > git commit -m "Add docs"

    [doc 4322962] Add docs 1 file changed, 1 insertion(+)
  41. > git add . > git commit -m "Add docs"

    [doc 4322962] Add docs 1 file changed, 1 insertion(+)
  42. > git add . > git commit -m "Add docs"

    [doc 4322962] Add docs 1 file changed, 1 insertion(+) … master doc
  43. > git checkout master Switched to branch 'master' > vim

    hello.cpp > git diff diff --git a/hello.cpp b/hello.cpp index 205ec4e..0c03ed4 100644 --- a/hello.cpp +++ b/hello.cpp @@ -2,6 +2,6 @@ int main() { - std::cout << "Hello, World!" << std::endl; + std::cout << "Hello World!" << std::endl; return 0; }
  44. > git add . > git commit -m "No comma

    plz" [master 8b13a27] No comma plz 1 file changed, 1 insertion(+), 1 deletion(-)
  45. > git add . > git commit -m "No comma

    plz" [master 8b13a27] No comma plz 1 file changed, 1 insertion(+), 1 deletion(-) … master doc
  46. > git merge doc Auto-merging hello.cpp Merge made by the

    'recursive' strategy. hello.cpp | 1 + 1 file changed, 1 insertion(+) … doc master
  47. > git checkout -b yolo > vim README.txt > git

    add . > git diff --staged diff --git a/README.txt b/README.txt index 033103a..d2b6d6d 100644 --- a/README.txt +++ b/README.txt @@ -1,9 +1,11 @@ MyProject ========= -This is my awesome project. +This is my awful project. Compile ------- make + +Run with ./hello.
  48. > git checkout -b yolo > vim README.txt > git

    add . > git commit -m "Better README" > git checkout master
  49. > git checkout -b yolo > vim README.txt > git

    add . > git commit -m "Better README" > git checkout master
  50. > git checkout -b yolo > vim README.txt > git

    add . > git commit -m "Better README" > git checkout master diff --git a/README.txt b/README.txt index 033103a..8187df5 100644 --- a/README.txt +++ b/README.txt @@ -1,9 +1,10 @@ MyProject ========= -This is my awesome project. +This is my super awesome project. Compile ------- + make clean make > vim README.txt > git diff
  51. > git checkout -b yolo > vim README.txt > git

    add . > git commit -m "Better README" > git checkout master > vim README.txt > git diff > git add . > git commit -m "Improved README"
  52. > git checkout -b yolo > vim README.txt > git

    add . > git commit -m "Better README" > git checkout master > vim README.txt > git diff > git add . > git commit -m "Improved README" … master yolo
  53. diff --git a/README.txt b/README.txt index 033103a..8187df5 100644 --- a/README.txt +++

    b/README.txt @@ -1,9 +1,10 @@ MyProject ========= -This is my awesome project. +This is my super awesome project. Compile ------- + make clean make > git show master > git show yolo diff --git a/README.txt b/README.txt index 033103a..d2b6d6d 100644 --- a/README.txt +++ b/README.txt @@ -1,9 +1,11 @@ MyProject ========= -This is my awesome project. +This is my awful project. Compile ------- make + +Run with ./hello.
  54. … master yolo > git merge yolo Auto-merging README.txt CONFLICT

    (content): Merge conflict in README.txt Recorded preimage for 'README.txt' Automatic merge failed; fix conflicts and then commit the result.
  55. > cat README.txt MyProject ========= <<<<<<< HEAD This is my

    super awesome project. ======= This is my awful project. >>>>>>> yolo Compile ------- make clean make Run with ./hello.
  56. > cat README.txt MyProject ========= <<<<<<< HEAD This is my

    super awesome project. ======= This is my awful project. >>>>>>> yolo Compile ------- make clean make Run with ./hello. conflit }
  57. > cat README.txt MyProject ========= Compile ------- make clean make

    Run with ./hello. conflit } This is my super awesome project. (résolu)
  58. > cat README.txt > git add . > git commit

    -m "merge 'yolo'" Recorded preimage for 'README.txt' [master f4d0975] merge 'yolo'
  59. > cat README.txt > git add . > git commit

    -m "merge 'yolo'" Recorded preimage for 'README.txt' [master f4d0975] merge 'yolo' > git branch -d yolo Deleted branch yolo (was 6e00883).
  60. > git log --oneline --graph * f4d0975 merge 'yolo' |\

    | * 6e00883 Better README * | a710abb Improved README |/ * 617dce9 Merge branch 'doc' |\ | * 4322962 Add docs * | 8b13a27 No comma plz |/ * dcbfea1 Better README * 1365375 README: Add compilation instructions * e0b1888 Makefile: Add 'clean' target * 622f151 Add Makefile * f8f6ceb Add hello.cpp * bf366d7 remove stuff * 50b4a18 move stuff * dc3bcbe initial commit
  61. > git log --oneline --graph * f4d0975 merge 'yolo' |\

    | * 6e00883 Better README * | a710abb Improved README |/ * 617dce9 Merge branch 'doc' |\ | * 4322962 Add docs * | 8b13a27 No comma plz |/ * dcbfea1 Better README * 1365375 README: Add compilation instructions * e0b1888 Makefile: Add 'clean' target * 622f151 Add Makefile * f8f6ceb Add hello.cpp * bf366d7 remove stuff * 50b4a18 move stuff * dc3bcbe initial commit
  62. Recap complet git init git status (--short) git help <commande>

    git add <fichier> git reset -- <fichier> git commit -m "message" git mv git rm git log (--oneline) (--summary) (--graph) git show <commit ou branche> git diff (--staged) (--word-diff) git clone git pull (<remote> <branche>) git push ((-u) <remote> <branche>) git remote (add <remote> <url>) git branch ((-d) <branche>) git checkout (-b) <branche> git merge
  63. Recap complet git init git status (--short) git help <commande>

    git add <fichier> git reset -- <fichier> git commit -m "message" git mv git rm git log (--oneline) (--summary) (--graph) git show <commit ou branche> git diff (--staged) (--word-diff) git clone git pull (<remote> <branche>) git push ((-u) <remote> <branche>) git remote (add <remote> <url>) git branch ((-d) <branche>) git checkout (-b) <branche> git merge Aller plus loin
  64. Recap complet git init git status (--short) git help <commande>

    git add <fichier> git reset -- <fichier> git commit -m "message" git mv git rm git log (--oneline) (--summary) (--graph) git show <commit ou branche> git diff (--staged) (--word-diff) git clone git pull (<remote> <branche>) git push ((-u) <remote> <branche>) git remote (add <remote> <url>) git branch ((-d) <branche>) git checkout (-b) <branche> git merge Aller plus loin git tag git alias git rebase git cherry-pick git bisect git blame git fetch git stash .gitignore

More Decks by Baptiste Fontaine

Other Decks in Education