diff --git a/Makefile b/Makefile index bccff20173917b5e860d910565b567ed2cf7663a..c16e0dd46fe35d700ce7961ded4756dbbd0d023d 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,9 @@ +BEAMEROPTIONS = -t beamer +BEAMEROPTIONS += --pdf-engine=pdflatex +BEAMEROPTIONS += --default-image-extension=pdf +BEAMEROPTIONS += -V theme:metropolis +BEAMEROPTIONS += -V themeoptions:numbering=none -V themeoptions:progressbar=foot +BEAMEROPTIONS += -V fontsize=smaller + default: git_tutorial.md - pandoc -s -t beamer -o git_tutorial.pdf git_tutorial.md --highlight-style kate --filter=pandoc-numbering --number-sections --filter=$(PANDOC_CROSSREF)pandoc-crossref \ No newline at end of file + pandoc -s $(BEAMEROPTIONS) -o git_tutorial.pdf git_tutorial.md \ No newline at end of file diff --git a/git_tutorial.md b/git_tutorial.md index 14f3aa27db3e5d3c3d79e8919f55cd4af071b3fd..08ac74e4332df4fc6b7d816e84633117d5f0c7cb 100644 --- a/git_tutorial.md +++ b/git_tutorial.md @@ -4,19 +4,19 @@ Il existe énormément de très bons documents et tutoriels en ligne: -- https://git-scm.com/ -- +- [https://git-scm.com/](https://git-scm.com/) +- [https://try.github.io/](https://try.github.io/) Des tas de repo en ligne: -- https://githepia.hesge.ch -- https://www.github.com -- https://www.gitlab.com +- [Githepia](https://githepia.hesge.ch) +- [Githhub](https://www.github.com) +- [Gitlab](https://www.gitlab.com) Et des GUI assez utiles: -- GitExtensions: https://gitextensions.github.io/ -- GitKraken: https://www.gitkraken.com/ +- [GitExtensions](https://gitextensions.github.io/) +- [GitKraken](https://www.gitkraken.com/) # Qu'est-ce que Git? @@ -43,5 +43,162 @@ Typiquement un projet git possède un serveur "officiel" géré par l'administra - Modifier localement le projet et publier (push) ses propres modifications (sur son serveur à lui). - Demander au gestionnaire du projet de fusionner (merge) ses modifications avec le serveur "officiel" (pull request): - L'administrateur récupère le projet depuis le serveur du développeur. - - Fusionne le projet officiel avec celui modifié. - - Publie les modifications sur le serveur officiel. \ No newline at end of file + - Fusionne le projet officiel avec celui modifié (merge). + - Publie les modifications sur le serveur officiel (push). + +# Exemple de fonctionnement + +## Création du dépôt et clone + +1. Création d'un dépôt *tutorial* git sur [https://githepia.hesge.ch](https://githepia.hesge.ch). +2. Clone du dépôt. + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.bash .numberLines} +$ git clone ssh://git@ssh.hesge.ch:10572/orestis.malaspin/tutorial.git +Cloning into 'tutorial'... +warning: You appear to have cloned an empty repository. +$ cd tutorial +[tutorial]$ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +3. Et voilà vous êtes dans votre dépôt git. + +# Ajout de fichiers à l'historique (1/3) + +## Commandes: `git add`, `git status`, `git commit`, `git push` + +1. Création du fichier `premierfichier.c`. +2. Ajout du `premierfichier.c` aux fichiers suivis par git. +3. *Commit* du fichier ajouté à l'historique des modifications. +4. *Push* de l'état de l'historique sur le serveur. +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.bash .numberLines} +[tutorial]$ echo Hello World > premierfichier.c +[tutorial]$ git status +On branch master + +No commits yet + +Untracked files: + (use "git add <file>..." to include in what will be committed) + + premierfichier.c + +nothing added to commit but untracked files present (use "git add" to track) + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# Ajout de fichiers à l'historique (2/3) + +## Commandes: `git add`, `git status`, `git commit`, `git push` + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.bash .numberLines} +[tutorial]$ git add premierfichier.c +[tutorial]$ git status +On branch master + +No commits yet + +Changes to be committed: + (use "git rm --cached <file>..." to unstage) + + new file: premierfichier.c + +[tutorial]$ git commit -m "mon premier commit" +[master (root-commit) a4f2052] mon premier commit + 1 file changed, 1 insertion(+) + create mode 100644 premierfichier.c +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# Ajout de fichiers à l'historique (3/3) + +## Commandes: `git add`, `git status`, `git commit`, `git push` + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.bash .numberLines} +[tutorial]$ git status +On branch master +Your branch is based on 'origin/master', but the upstream is gone. + (use "git branch --unset-upstream" to fixup) + +nothing to commit, working tree clean +[tutorial]$ git push +Counting objects: 3, done. +Writing objects: 100% (3/3), 238 bytes | 238.00 KiB/s, done. +Total 3 (delta 0), reused 0 (delta 0) +To ssh://ssh.hesge.ch:10572/orestis.malaspin/tutorial.git + * [new branch] master -> master +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + +# Modification de fichiers dans l'historique (1/3) + +## Commandes: `git diff`, `git log` + +1. Modification du fichier `premierfichier.c`. +2. Ajout/commit/push des modifictations. + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.bash .numberLines} +[tutorial]$ echo Wild World > premierfichier.c +[tutorial]$ git status +On branch master +Your branch is up to date with 'origin/master'. + +Changes not staged for commit: + (use "git add <file>..." to update what will be committed) + (use "git checkout -- <file>..." to discard changes in working directory) + + modified: premierfichier.c + +no changes added to commit (use "git add" and/or "git commit -a") +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# Modification de fichiers dans l'historique (2/3) + +## Commandes: `git diff`, `git log` + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.bash .numberLines} +[tutorial]$ git diff +diff --git a/premierfichier.c b/premierfichier.c +index 557db03..9622e40 100644 +--- a/premierfichier.c ++++ b/premierfichier.c +@@ -1 +1 @@ +-Hello World ++Wild World +[tutorial]$ git commit -am "nouvelles modifications" +[master f9ab3ec] nouvelles modifications + 1 file changed, 1 insertion(+), 1 deletion(-) +[tutorial]$ git push +Counting objects: 3, done. +Writing objects: 100% (3/3), 274 bytes | 274.00 KiB/s, done. +Total 3 (delta 0), reused 0 (delta 0) +To ssh://ssh.hesge.ch:10572/orestis.malaspin/tutorial.git + a4f2052..f9ab3ec master -> master +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# Modification de fichiers dans l'historique (3/3) + +## Commandes: `git diff`, `git log` + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.bash .numberLines} +[tutorial]$ git log +commit f9ab3ec4a00c46a12d7a45f133295acc5fb5cd20 (HEAD -> master, origin/master) +Author: Orestis Malaspinas <orestis.malaspinas@hesge.ch> +Date: Sun Mar 4 22:48:21 2018 +0100 + + nouvelles modifications + +commit a4f2052147a752a8c12641f4f3352c5aa1802559 +Author: Orestis Malaspinas <orestis.malaspinas@hesge.ch> +Date: Sun Mar 4 22:25:24 2018 +0100 + + mon premier commit +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# Revenir en arrière dans l'historique (1/3) + +## Commandes: `git checkout`, `git reset` + +1. Faire une modification dans un fichier qu'on aurait pas dû faire. +2. Faire un `git add` qu'on aurait pas dû faire. +3. Faire un `git commit` qu'on aurait pas dû faire. +