branching_handouts.tex 2.32 KB
Newer Older
1 2
\documentclass{article}

3
\providecommand{\handoutsTitle}{Working with branches in Git}
4

5 6
\usepackage{handouts}
\input{../shared/shared}
7

8 9
\begin{document}
\makeHeader
10

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

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

27
\subsubsection*{Implement a feature in a new branch}
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

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

\begin{itemize}
53 54
  \item \emph{Question:} If you want to merge branch \lstinline{B} into branch
    \lstinline{A}, what should be your current branch?
55 56 57
\end{itemize}
\bigskip

58
Merge your feature branch into \lstinline{master}.
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

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}

87
\end{document}