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

Laros's avatar
Laros committed
3
\providecommand{\handoutsTitle}{Working with branches in Git}
Vermaat's avatar
Vermaat committed
4

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

Laros's avatar
Laros committed
8 9
\begin{document}
\makeHeader
Vermaat's avatar
Vermaat committed
10

Laros's avatar
Laros committed
11
\subsubsection*{Inspect the commit graph}
Vermaat's avatar
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
Vermaat's avatar
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?
Vermaat's avatar
Vermaat committed
19
\end{itemize}
Laros's avatar
Laros committed
20
\emph{Hint:} Use \lstinline{git log} with the appropriate arguments.
Vermaat's avatar
Vermaat committed
21 22
\bigskip

Laros's avatar
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

Laros's avatar
Laros committed
27
\subsubsection*{Implement a feature in a new branch}
Vermaat's avatar
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

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

\begin{itemize}
Laros's avatar
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?
Vermaat's avatar
Vermaat committed
55 56 57
\end{itemize}
\bigskip

Laros's avatar
Laros committed
58
Merge your feature branch into \lstinline{master}.
Vermaat's avatar
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

Laros's avatar
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}

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