Commit 0960f372 authored by Grégory Mounié's avatar Grégory Mounié
Browse files

Merge branch 'master' of gricad-gitlab.univ-grenoble-alpes.fr:mounieg/formation-git

parents 3851037d 131f1c58
PDFLATEX_OPTIONS= -shell-escape
FILES=(git-computer-lab.pdf README.org)
FILES= git-computer-lab.pdf README.org
include LaTeX.mk
upload-gitlab: $(FILE)
upload-gitlab: $(FILES)
ls /tmp/www-git || ( cd /tmp/ && git clone git@gitlab.ensimag.fr:systemes/www-git.git )
cd /tmp/www-git && git pull
cp -a avance $(FILES) /tmp/www-unix/public/
cp -a $(FILES) /tmp/www-unix/public/
@printf "Documents copié dans /tmp/www-unix\n Penser à y faire git commit et git push pour les pousser vers gitlab"
......@@ -14,41 +14,7 @@
#+SETUPFILE: https://fniessen.github.io/org-html-themes/setup/theme-readtheorg.setup
* Introduction to Git
The best book on Git, for freely available: https://git-scm.com/book/en/v2
This page contains few exercices to:
- understand why Version Control Software are so important in modern
computer science
- understand the basics of Git
** A small Git presentation [Matthieu Moy]
- 4 per page :: http://systemes.pages.ensimag.fr/www-unix/avance/seance1-git/Slides/git-handout.pdf
- beamer :: http://systemes.pages.ensimag.fr/www-unix/avance/seance1-git/Slides/git-slides.pdf
** Git and gitlab basics
*** Exercice
(remplacer http://gitlab.ensimag.fr par http://gricad-gitlab.imag.fr )
- http://systemes.pages.ensimag.fr/www-unix/avance/seance1-git/seance-machine-git.pdf
- http://systemes.pages.ensimag.fr/www-unix/avance/seance1-git/sandbox.tar.gz
# ** Practical 2: standalone git
** Git: branches
*** Explanations
http://recherche.noiraudes.net/resources/git/Slides/git-workflow-slides.pdf
*** Practical
- TP :: http://recherche.noiraudes.net/resources/git/Slides/git-workflow-slides.pdf
** Practical 4: Git: under the hood
** Git tools
http://recherche.noiraudes.net/resources/git/Slides/git-tools-slides.pdf
** Git configuration
http://recherche.noiraudes.net/resources/git/Slides/configuring-git-slides.pdf
* Introduction à Git
* M1 Info: Introduction à Git
Le meilleur livre sur Git librement disponible
https://git-scm.com/book/en/v2
......@@ -95,3 +61,42 @@
** Git configuration (en anglais)
http://recherche.noiraudes.net/resources/git/Slides/configuring-git-slides.pdf
* M1 MOSIG: Introduction to Git
The best book on Git, freely available: https://git-scm.com/book/en/v2
This page contains few exercices to:
- understand why Version Control Software are so important in modern
computer science
- understand the basics of Git
** A small Git presentation [Matthieu Moy]
- 4 per page :: http://systemes.pages.ensimag.fr/www-unix/avance/seance1-git/Slides/git-handout.pdf
- beamer :: http://systemes.pages.ensimag.fr/www-unix/avance/seance1-git/Slides/git-slides.pdf
** Git and gitlab basics
*** Practical
(Please remplace http://gitlab.ensimag.fr by http://gricad-gitlab.imag.fr if relevant)
Default exercises: http://systemes.pages.ensimag.fr/www-git/git-computer-lab.pdf
- Sandbox: http://systemes.pages.ensimag.fr/www-unix/avance/seance1-git/sandbox.tar.gz
# ** Practical 2: standalone git
** Git: branches
*** Explanations
http://recherche.noiraudes.net/resources/git/Slides/git-workflow-slides.pdf
*** Practical in French
http://systemes.pages.ensimag.fr/www-unix/avance/seance1-git-bonus/tp1-flow.pdf
** Git: under the hood
*** Explanation
- http://recherche.noiraudes.net/resources/git/Slides/understanding-git-slides.pdf
*** Practical in French
http://recherche.noiraudes.net/resources/git/TP/tp1-modele-git.pdf
** Git tools
http://recherche.noiraudes.net/resources/git/Slides/git-tools-slides.pdf
** Git configuration
http://recherche.noiraudes.net/resources/git/Slides/configuring-git-slides.pdf
......@@ -53,11 +53,11 @@ An extended self-content french version of this document is available here~:\\
\section{Git and Version Control System}
Git is a Version Control Sytem, that is a software designed to manage
Git is a Version Control System, that is a software designed to manage
the changes to textual documents like the source code of programs.
In the english version of this document, we will often refer to
chapters of the web version of {\em Pro Git Book}
In the English version of this document, we often refer to
some chapters of the web version of {\em Pro Git Book}
at \url{https://git-scm.com/book/en/v2}. This book is freely available in
electronic form (Creative Common NC SA 3.0).
......@@ -67,14 +67,14 @@ and
\href{https://git-scm.com/book/en/v2/Getting-Started-What-is-Git%3F}{Chapter 1.3}
\href{https://en.wikipedia.org/wiki/Comparison_of_version-control_software}{Numerous VCS exists},
Numerous VCS, \href{https://en.wikipedia.org/wiki/Comparison_of_version-control_software}{listed in Wikipedia}, exist,
but Git is the most commonly used, now.
For the following of sections of this practical, we will used a {\em
Gitlab server}. Gitlab has similar functionalities to Github, but is
For the following of sections of this document, we use a {\em
Gitlab server}. Gitlab has similar functionalities to GitHub. But, it is
a free software, and thus many institutions deploy it. If you have a
computer account at Ensimag, you will use
computer account at Ensimag, you use
\url{https://gitlab.ensimag.fr}. If you have a computer account at
UGA, you may also use
\url{https://gricad-gitlab.univ-grenoble-alpes.fr}. Finally, you may
......@@ -85,10 +85,10 @@ open an account, and use \url{https://gitlab.com}.
\begin{description}
\item[Git newbies] group yourself in small teams of at least two
people, with two computers close to each other.
\item[Git experts] group yourself in small teams and do alone some
\item[Git experts] group yourself in small teams and do some
others practical exercises of the web page of this lecture.
\end{description}
\subsection{Organisation}
\subsection{Team organization}
A team will use two Linux PC close to each other (using your own
laptop is perfectly fine). The gitlab server is freely accessible at
......@@ -96,7 +96,7 @@ any time from any places. The git repository of the team is assumed
to be in \texttt{gitlab.ensimag.fr}.
Let us assume that the team is composed of two people, \texttt{Alive}
Let us assume that the team is composed of two people, \textit{Alice}
on \texttt{laptop1} and \textit{Bob} on \texttt{laptop2}. Explanations
may be extended to any number of team members.
......@@ -135,20 +135,20 @@ of \textit{Bob}\\
Gitlab may used the \texttt{https} protocol, or the \texttt{ssh}
protocol.
Using the \texttt{ssh} protocol, you will avoid to type your password
Using the \texttt{ssh} protocol, you avoid typing your password
at every Git transfer.
You need first to create your own public-private pair of ssh keys.
Read now the chapter \url{https://git-scm.com/book/en/v2/Git-on-the-Server-Generating-Your-SSH-Public-Key}
Read now \href{https://git-scm.com/book/en/v2/Git-on-the-Server-Generating-Your-SSH-Public-Key}{the Chapter 4.3}
\begin{itemize}
\item If you do not have it yet, create a public-private key pair with
\item If you do not have one yet, create a public-private key pair with
\texttt{ssh-keygen}. Choose a good passphrase. A sentence, or few
words, that you will never forget, are perfectly fine. The good
practice is to create a different key pair per computer, or computer
account.
Thus now, you should have two files \texttt{id\_rsa.pub} (public
Thus, now, you should have two files \texttt{id\_rsa.pub} (public
part) and \texttt{id\_rsa} (private part) in your directory
\texttt{\textasciitilde/.ssh}.
......@@ -173,7 +173,7 @@ Enter passphrase for /home/petrot/.ssh/id_rsa:
\item Copy the public key, the content of \texttt{id\_rsa.pub}, in your
account on \url{https://gitlab.ensimag.fr}. In your \emph{User
Settings} (Menu top right, third entry) you will find a section
Settings} (Menu top right, third entry) you find a section
\emph{SSH Keys} (Menu on the left). Copy-paste the public key in the
form. Choose a name and click on \texttt{Add key}.
\end{itemize}
......@@ -184,14 +184,14 @@ On your own computer, to use Git, you will have to install it
first. Under Ubuntu or Debian « \texttt{apt-get install git gitk} » ou
« \texttt{apt-get install git-core gitk} ».
Details on the Git configuration are presented in Chapter 8.1
Details on the Git configuration are presented in
\href{https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration}{Chapter 8.1}.
Create or edit the \texttt{\textasciitilde/.gitconfig} file:
\begin{minted}{bash}
emacs ~/.gitconfig # or your favorite editor
emacs ~/.gitconfig # or use your favorite editor
\end{minted}
Add at least \texttt{.gitconfig} the following content:
Add, in \texttt{.gitconfig}, at least, the following content:
\begin{minted}{ini}
[core]
......@@ -216,14 +216,13 @@ Add at least \texttt{.gitconfig} the following content:
pager = true
\end{minted}
Beware of modern editor already running. If the editor command finish
early, Git will return
Beware of "modern" editor already running when committing. If the editor command finishes early, Git will display
\begin{verbatim}
Aborting commit due to empty commit message.
\end{verbatim}
and nothing will be registered.
The section \texttt{[push]} is there only to homogenize the behavior of old Git version.
The section \texttt{[push]} is only there to homogenize the behavior of old Git version.
\section{Starting a new project}
......@@ -233,7 +232,7 @@ should do it.
\subsection{Shared repository creation in Gitlab}
\label{sec=creation-depot-partagee}
\textit{Alice} will connect to her account on \texttt{gitlab.ensimag.fr}:
\textit{Alice} connects to her account on \texttt{gitlab.ensimag.fr}:
\begin{minted}{console}
alice@laptop1$ firefox gitlab.ensimag.fr
......@@ -251,7 +250,7 @@ the default in Gitlab.
Using the « Groups » button, \textit{Alice} add \textit{Bob} as team
member: left menu \emph{Members}, then add Bob in \emph{Add new
member}. \textit{Bob} will have the same role as \textit{Alice}:
member}. \textit{Bob} has the same role as \textit{Alice}:
\emph{Owner}.
Note: \textit{Bob} may have to connect at least once to Gitlab before
......@@ -262,9 +261,9 @@ bob@laptop2$ firefox gitlab.ensimag.fr
\subsubsection{Repository creation}
Using the menu/button « + », Alice creates an empty projet (\emph{New project}). the project name is \texttt{project1} under the group \verb!alice_bob!.
Using the menu/button « + », Alice creates an empty project (\emph{New project}). The project name is \texttt{project1}, under the group \verb!alice_bob!.
Now, Alice and Bob will work directly in their HOME.
Now, Alice and Bob work directly in their HOME.
The figure \ref{fig:git} presents the typical exchanges and states of the files.
\footnote{\url{https://git-scm.com/book/en/v2/Getting-Started-Git-Basics}\\
......@@ -279,7 +278,7 @@ Git has three main states that your files can reside in: committed, modified, an
\begin{figure}[H]
\centering
\input{git-sequence.tikz}
\caption{Working dir, staging area (index) and reposotory}
\caption{Working directory, staging area (index) and repository}
\label{fig:git}
\end{figure}
......@@ -290,7 +289,7 @@ Git has three main states that your files can reside in: committed, modified, an
As the project is empty, there is no file in it. \textit{Alice} adds
the first files as the first step.
\textit{Alice} clone the remote repository to create her working
\textit{Alice} clones the remote repository to create her working
directory \verb|~/project1|:
{\small
......@@ -304,7 +303,7 @@ subdirectory \texttt{.git/} with the Git meta-data and file history.
Alice downloads the directory \texttt{sandbox/} (at
\url{https://ensiwiki.ensimag.fr/index.php/Fichier:Sandbox.tar.gz}),
extract it and add it to the Git history.
extracts it and adds it to the Git history.
\begin{minted}{console}
alice@laptop1$ wget https://ensiwiki.ensimag.fr/images/8/86/Sandbox.tar.gz
......@@ -357,11 +356,11 @@ add their name at the top and save the file.
\subsection{Commit creation}
The command:
\begin{minted}{bash}
git status # comparaison of working directory and history
\end{minted}
produce~:
should display:
\begin{verbatim}
On branch master
Changes not staged for commit:
......@@ -376,7 +375,7 @@ Changes not staged for commit:
registered in the local history.
{\em Alice} and {\em Bob} look at the details of the differences
between current state of the file and its last state in history:
between the current state of the file and its last state in history:
\begin{minted}{bash}
git diff HEAD
\end{minted}
......@@ -398,15 +397,15 @@ index a47665a..7f67d33 100644
\end{verbatim}
Lines starting with '-' are removed from previous commit.
Lines starting with '+' are added to previous commit.
Lines starting with '+' are added from previous commit.
Now, both, {\em Alice} and {\em Bob} create a new commit~:
\begin{minted}{bash}
git commit -a # register all modifications of the local repository
\end{minted}
The editor start. They have to write a log message. A good log message
start with a title line, then a blank line, than a short text. The log
The editor starts. They have to write a log message. A good log message
start with a title line, then a blank line, then a short text. The log
message should explain the reason of the modification (Why).
After saving the message and quitting the editor, they read in their terminal:
......@@ -442,21 +441,21 @@ First, \textbf{ONLY} {\em Bob} publishes its commit~:
bob@laptop2$ git push # send the Bob commit to shared repository
\end{minted}
{\em Alice} and {\em Bob} should follow change in the local history:
{\em Alice} and {\em Bob} should follow changes in the local history with:
%Pour voir où on en est, les deux équipes peuvent lancer la commande~:
\begin{minted}{bash}
gitk # graphical history
\end{minted}
or with
or with:
\begin{minted}{bash}
git log # textual history.
\end{minted}
Second, {\em Alice} attempts to publish her modifications~:
Second, {\em Alice} attempts to publish her modification:
\begin{minted}{console}
alice@laptop1$ git push
\end{minted}
The publication should failed~:
The publication should fail:
\begin{verbatim}
To ssh://git@gitlab.ensimag.fr/alice_bob/project1.git
! [rejected] master -> master (non-fast forward)
......@@ -470,12 +469,12 @@ Merge the remote changes (e.g. 'git pull') before pushing again. See the
{\em Alice} has first to merge {\em Bob} modifications already published.
{\em Alice} do the merge~:
{\em Alice} does the merging of the version:
\begin{minted}{console}
alice@laptop1$ git pull
\end{minted}
{\em Alice} and {\em Bob} have change the same lines, thus the
{\em Alice} and {\em Bob} have changed the same lines, thus the
automatic merge should fail.
\begin{verbatim}
......@@ -484,16 +483,16 @@ CONFLICT (content): Merge conflict in sandbox/hello.c
Automatic merge failed; fix conflicts and then commit the result.
\end{verbatim}
La bonne nouvelle, c'est que les modifications faites par \textit{Alice} et Bob
sur des endroits différents du fichier ont été fusionnées. Quand une
équipe est bien organisée et évite de modifier les mêmes endroits en
même temps, ce cas est le plus courant~: les développeurs font les
modifications, et le gestionnaire de versions fait les fusions
automatiquement.
The good news: the modifications at different lines are already merged.
{\em Alice} has to set \texttt{hello.c} to the correct version by
hand. Hopefully, problematic lines are well indicated in the file.
% La bonne nouvelle, c'est que les modifications faites par \textit{Alice} et Bob
% sur des endroits différents du fichier ont été fusionnées. Quand une
% équipe est bien organisée et évite de modifier les mêmes endroits en
% même temps, ce cas est le plus courant~: les développeurs font les
% modifications, et le gestionnaire de versions fait les fusions
% automatiquement.
The bad news: {\em Alice} has to set \texttt{hello.c} to the correct version by
hand. Hopefully, problematic lines are clearly indicated in the file.
\begin{minted}{diff}
<<<<<<< HEAD
/* Auteurs : Alice et ... */
......@@ -507,12 +506,11 @@ hand. Hopefully, problematic lines are well indicated in the file.
/* Auteurs : Alice et Bob */
\end{verbatim}
%Si {\em Alice} fait à nouveau
Then
\begin{minted}{console}
alice@laptop1$ git status
\end{minted}
should display~:
should display:
\begin{verbatim}
On branch master
Your branch and 'origin/master' have diverged,
......@@ -526,10 +524,9 @@ Unmerged paths:
no changes added to commit (use "git add" and/or "git commit -a")
\end{verbatim}
To be sure of the results, {\em Alice} check the differences:
To be sure of the results, {\em Alice} checks the differences:
\begin{minted}{bash}
git diff # git diff sans argument, alors qu'on avait
# l'habitude d'appeler 'git diff HEAD'
git diff # and not 'git diff HEAD'
\end{minted}
The result looks like:
\begin{verbatim}
......@@ -562,28 +559,24 @@ Changes to be committed:
\end{verbatim}
Then, {\em Alice} finishes to build the merge commit:
Then, {\em Alice} finishes building the commit of the merging:
\begin{minted}{bash}
git commit
\end{minted}
The default message is sufficient.
The default message is sufficient. {\em Alice} \/saves it and quits the editor.
Looking at the details:
\begin{minted}{bash}
gitk
\end{minted}
{\em Alice} logs show 3 commits: the two modifications and the merge.
La fusion étant faite, {\em Alice} peut mettre à disposition son travail
(le premier commit, manuel, et le commit de fusion) avec~:
{\em Alice}'s logs show 3 commits: the two modifications and the merge.
{\em Alice} publishes her repository state:
\begin{minted}{console}
alice@laptop1$ git push
\end{minted}
and {\em Bob} get it without a glinch:
and {\em Bob} get it without a glitch:
\begin{minted}{console}
bob@laptop2$ git pull
\end{minted}
......@@ -600,15 +593,11 @@ git push # do nothing: already up-to-date
\subsection{Add new files}
À présent, {\em Alice} crée un nouveau fichier, \texttt{toto.c},
avec un contenu quelconque.
{\em Alice} create a new file \texttt{toto.c} and do:
\begin{minted}{console}
alice@laptop1$ git status
\end{minted}
should display:
that should display:
\begin{verbatim}
On branch master
Untracked files:
......@@ -618,7 +607,7 @@ Untracked files:
nothing added to commit but untracked files present (use "git add" to track)
\end{verbatim}
To put it in the next commit, {\em Alice} has to mark him for tracking
To put it in the next commit, {\em Alice} has to mark it for tracking
first with \texttt{git add toto.c}:
\begin{minted}{console}
......@@ -635,8 +624,7 @@ Changes to be committed:
\end{verbatim}
{\em Alice} create the commit in one line, providing the message:
{\em Alice} creates the commit in one line, providing directly the message:
\begin{minted}{bash}
alice@laptop1$ git commit -m "ajout de toto.c"
\end{minted}
......@@ -651,7 +639,7 @@ should display:
\begin{minted}{console}
alice@laptop1$ git push
\end{minted}
{\em Bob} get the file with the following command:
{\em Bob} gets the file with the following command:
\begin{minted}{console}
bob@laptop2$ git pull
\end{minted}
......@@ -665,7 +653,7 @@ Fast forward
\subsection{Fichiers ignorés par Git}
\subsection{Ignoring some files in Git}
{\em Bob} creates a new file \texttt{temp-file.txt}.
......@@ -684,24 +672,24 @@ Untracked files:
nothing added to commit but untracked files present (use "git add" to track)
\end{verbatim}
If {\em Bob} do not want to track the file in the repository, he
If {\em Bob} doesn't want to track the file in the repository, he
should register in the repository that this file should be ignored.
He will add the file name into a file \texttt{.gitignore} in the same
He adds the file name into a file \texttt{.gitignore} in the same
directory.
{\em Bob} opens the file:
\begin{minted}{console}
bob@laptop2$ emacs .gitignore
\end{minted}
add the line:
adds the line:
\begin{verbatim}
temp-file.txt
\end{verbatim}
save and quit.
saves, and quits.
{\em Bob} do again the command:
{\em Bob} does again the command:
\begin{minted}{bash}
bob@laptop2$ git status
\end{minted}
......@@ -717,9 +705,9 @@ Changes to be committed:
The file \texttt{temp-file.txt} is now ignored. It is common to add all generated file in
the \texttt{.ignore} file like
\texttt{*.o *~ *.bak}.
\texttt{*.o *\textasciitilde\ *.bak}.
{\em Bob} should add and push the \texttt{.ignore} file.
{\em Bob} adds and pushes the \texttt{.ignore} file.
\section{Conclusion}
......
......@@ -8,11 +8,11 @@ width=2cm,align=center}]
\node[head,fill=blue!40,right=of sa, minimum height = 1.5cm] (lr) {local \\ repo};
\node[head,fill=red!40,right=2cm of lr, minimum height = 1.5cm] (rr) {remote \\ repo};
\node[above= 1 cm of rr,font={\bfseries}]{Depôt distant};
\node[above= 0.5 cm of rr]{(depots.ensimag.fr)};
\node[above= 1 cm of rr,font={\bfseries}]{Remote repository};
\node[above= 0.5 cm of rr]{(gitlab.ensimag.fr)};
\node[above= 1 cm of sa,font={\bfseries}]{Dépôt local};
\node[above= 0.5 cm of sa]{(ensipcXXX.ensimag.fr)};
\node[above= 1 cm of sa,font={\bfseries}]{Local repository};
\node[above= 0.5 cm of sa]{(laptop1 and laptop2)};
\begin{scope}[line width=2pt,gray]
\foreach \x in {wd,sa,lr,rr}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment