branching_handouts.tex 2.32 KB
Newer Older
Martijn Vermaat's avatar
Martijn Vermaat committed
1 2
\documentclass{article}

Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
3
\providecommand{\handoutsTitle}{Working with branches in Git}
Martijn Vermaat's avatar
Martijn Vermaat committed
4

Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
5 6
\usepackage{handouts}
\input{../shared/shared}
Martijn Vermaat's avatar
Martijn Vermaat committed
7

Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
8 9
\begin{document}
\makeHeader
Martijn Vermaat's avatar
Martijn Vermaat committed
10

Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
11
\subsubsection*{Inspect the commit graph}
Martijn Vermaat's avatar
Martijn Vermaat committed
12 13 14
We'll work from the repository you created in the previous practical.

\begin{itemize}
15
  \item \emph{Question:} What is your current branch and what is the hash of
Martijn Vermaat's avatar
Martijn Vermaat committed
16 17
    the commit it points to?
  \item \emph{Question:} What does the commit graph of you repository look
18
    like? Can you draw it on paper?
Martijn Vermaat's avatar
Martijn Vermaat committed
19
\end{itemize}
Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
20
\emph{Hint:} Use \lstinline{git log} with the appropriate arguments.
Martijn Vermaat's avatar
Martijn Vermaat committed
21 22
\bigskip

Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
23 24
As an alternative to \lstinline{git log}, you can also try a graphical viewer
such as \lstinline{gitg} (installed on the course laptops) or \lstinline{gitk}.
25 26
\bigskip

Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
27
\subsubsection*{Implement a feature in a new branch}
Martijn Vermaat's avatar
Martijn Vermaat committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
Let's do some real work (e.g., add some documentation to the project).
\bigskip

Start by creating a branch for your work (give it a descriptive name) and
switch to it.

\begin{itemize}
  \item \emph{Question:} What branches are there now and what are the commits
    they point to?
\end{itemize}
\bigskip

Implement your feature (e.g. write documentation) and commit your changes.

\begin{itemize}
  \item \emph{Question:} What does the commit graph of you repository look
    like now?
\end{itemize}
\bigskip

Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
48 49
\subsubsection*{Merge your feature}
Of course we want this nice feature in our \lstinline{master} branch.
Martijn Vermaat's avatar
Martijn Vermaat committed
50 51 52
\bigskip

\begin{itemize}
Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
53 54
  \item \emph{Question:} If you want to merge branch \lstinline{B} into branch
    \lstinline{A}, what should be your current branch?
Martijn Vermaat's avatar
Martijn Vermaat committed
55 56 57
\end{itemize}
\bigskip

Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
58
Merge your feature branch into \lstinline{master}.
Martijn Vermaat's avatar
Martijn Vermaat committed
59 60 61 62 63 64 65 66

\begin{itemize}
  \item \emph{Question:} What does the commit graph of you repository look
    like now?
\end{itemize}
\bigskip

Since you merged it, you can now delete the feature branch.
67 68
\bigskip

Jeroen F.J. Laros's avatar
Jeroen F.J. Laros committed
69
\subsubsection*{A three-way merge}
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
Unless you were extremely zealous, the last section produced a fast-forward
merge.
\bigskip

\begin{itemize}
  \item \emph{Question:} Can you think of a way to get a three-way merge?
\end{itemize}
\bigskip

Manipulate your repository in such a way that the commit graph contains a
merge commit (created by a three-way merge).

\begin{itemize}
  \item \emph{Question:} What does the commit graph of you repository look
    like now?
\end{itemize}

Martijn Vermaat's avatar
Martijn Vermaat committed
87
\end{document}