Commit 818df604 authored by Vermaat's avatar Vermaat
Browse files

Almost finished slides on branching

parent 40f9a83b
......@@ -21,6 +21,22 @@
\usetheme{lumc}
\lstset{
basicstyle=\ttfamily,
language=none,
frame=none,
numbers=none,
numbersep=0
}
\AtBeginSection[]
{
\begin{frame}
\frametitle{Table of contents}
\tableofcontents[currentsection]
\end{frame}
}
\begin{document}
% This disables the \pause command, handy in the editing phase.
......@@ -29,14 +45,15 @@
% Make the title page.
\bodytemplate
% First page of the presentation.
\section{The Git commit graph}
\begin{frame}
\frametitle{A linear history}
\includegraphics[width=10cm]{images/linear}
\begin{itemize}
\item Every commit has a parent
\item {\em Committing} creates a new commit on top of the current one
\item Every commit has a parent.
\item {\em Committing} creates a new commit on top of the current one.
\end{itemize}
\end{frame}
......@@ -44,17 +61,17 @@
\frametitle{The default \bt{master} branch}
\includegraphics[width=10cm]{images/master}
\begin{itemize}
\item A {\em branch} is a pointer to a commit
\item By default there is one branch: \bt{master}
\item A {\em branch} is a pointer to a commit.
\item By default there is one branch: \bt{master}.
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{The current commit: \bt{HEAD}}
\begin{itemize}
\item The current commit is called \bt{HEAD} (shown in blue)
\item \bt{HEAD} normally points to the current branch
\item Or to a commit if there is no current branch
\item The current commit is called \bt{HEAD} (shown in blue).
\item \bt{HEAD} normally points to the current branch.
\item Or to a commit if there is no current branch.
\end{itemize}
\vspace{1cm}
\includegraphics[width=10cm]{images/head}
......@@ -63,9 +80,9 @@
\begin{frame}
\frametitle{Committing moves \bt{HEAD} and the current branch}
\begin{itemize}
\item Committing moves the current branch to the new commit
\item Of course, \bt{HEAD} moves with it
\item If there is no current branch, only \bt{HEAD} moves
\item Committing moves the current branch to the new commit.
\item Of course, \bt{HEAD} moves with it.
\item If there is no current branch, only \bt{HEAD} moves.
\end{itemize}
\vspace{1cm}
\includegraphics[width=10cm]{images/commit}
......@@ -75,16 +92,16 @@
\frametitle{A non-linear history}
\includegraphics[width=10cm]{images/nonlinear}
\begin{itemize}
\item The commit graph can become non-linear
\item Usually by committing from the same commit twice
\item The commit graph can become non-linear.
\item Usually by committing from the same commit twice.
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Use branches to keep track of different code paths}
\begin{itemize}
\item Branch names are easier to remember than commit hashes
\item Branch names make it clear what commits are about
\item Branch names are easier to remember than commit hashes.
\item Branch names make it clear what commits are about.
\end{itemize}
\vspace{0.5cm}
\includegraphics[width=6cm]{images/branches}
......@@ -93,44 +110,268 @@
\begin{frame}
\frametitle{Different code paths may later join}
\begin{itemize}
\item Commits from different branches can be brought together
\item We call this {\em merging}
\item Commits from different branches can be brought together.
\item We call this {\em merging}.
\end{itemize}
\vspace{0.5cm}
\includegraphics[width=6cm]{images/merge}
\end{frame}
\section{Managing branches}
\section{Inspecting the commit graph}
% todo: listing branches, showing current branch
\begin{frame}
\frametitle{An example repository}
\includegraphics[width=8cm]{images/example}
\begin{itemize}
\item Branches \bt{license} and \bt{interface} diverged from \bt{master}.
\item Only \bt{license} has been merged back into \bt{master}.
\item Current branch is \bt{master}.
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Showing the current branch: \bt{git status}}
\begin{lstlisting}
$ git status
# On branch master
nothing to commit (working directory clean)
\end{lstlisting}
\bigskip
Remember: you cannot type \bt{git status} enough!
\end{frame}
\begin{frame}[fragile]
\frametitle{Listing branches: \bt{git branch}}
\begin{lstlisting}
$ git branch
interface
license
* master
\end{lstlisting}
\bigskip
Three branches, current branch is \bt{master}.
\pause
\bigskip
\begin{lstlisting}
$ git branch -v
interface 8fc25c1 Trivial Python interface
license 0fbe3e3 Add MIT license
* master c7f3bd9 Add .gitignore file
\end{lstlisting}
\bigskip
\bt{-v}: Shows the commit each branch points to.
\end{frame}
\begin{frame}[fragile]
\frametitle{The commit log: \bt{git log}}
\begin{lstlisting}
$ git log --oneline --decorate
c7f3bd9 (HEAD, master) Add .gitignore file
4a44c4e Merge branch 'license'
64af1ee Add course teachers to README
0fbe3e3 (license) Add MIT license
d1c7fd7 Initial commit with README
\end{lstlisting}
\bigskip
\bt{--oneline}: Shows commit summary on one line.
\bt{--decorate}: Adds branch information.
\end{frame}
\begin{frame}[fragile]
\frametitle{The commit log as a graph: \bt{git log}}
\begin{lstlisting}
$ git log --oneline --decorate --graph --all
* 8fc25c1 (interface) Trivial Python interface
| * c7f3bd9 (HEAD, master) Add .gitignore file
|/
* 4a44c4e Merge branch 'license'
|\
| * 0fbe3e3 (license) Add MIT license
* | 64af1ee Add course teachers to README
|/
* d1c7fd7 Initial commit with README
\end{lstlisting}
\bigskip
\bt{--graph}: Shows the commit graph.
\bt{--all}: Includes all branches instead of just the current.
\end{frame}
\begin{frame}[fragile]
\frametitle{Switching to another branch: \bt{git checkout}}
\begin{lstlisting}[language=none]
git checkout mybranch
\begin{lstlisting}
$ git checkout interface
Switched to branch 'interface'
\end{lstlisting}
\bigskip
This points \bt{HEAD} to the named branch and updates your working
directory.
\pause
\bigskip
\begin{lstlisting}
$ git status
# On branch interface
nothing to commit (working directory clean)
\end{lstlisting}
\end{frame}
\section{Manipulating the commit graph}
\begin{frame}
\frametitle{An example repository}
\includegraphics[width=8cm]{images/example}
\begin{itemize}
\item Makes \bt{mybranch} the current branch (and moves \bt{HEAD})
\item Branches \bt{license} and \bt{interface} diverged from \bt{master}.
\item Only \bt{license} has been merged back into \bt{master}.
\item Current branch is \bt{master}.
\end{itemize}
\vspace{0.5cm}
\includegraphics[width=10cm]{images/checkout}
\end{frame}
\begin{frame}[fragile]
\frametitle{Creating a new branch: \bt{git branch}}
\begin{lstlisting}[language=none]
git branch mybranch
\begin{lstlisting}
$ git branch lib
\end{lstlisting}
\bigskip
Creates branch \bt{lib} at \bt{HEAD}.
\pause
\bigskip
\begin{lstlisting}
$ git checkout lib
Switched to branch 'lib'
\end{lstlisting}
\pause
\bigskip
Or, for Git pro's, in one command:
\bigskip
\begin{lstlisting}
$ git checkout -b lib
Switched to a new branch 'lib'
\end{lstlisting}
\bigskip
At this point, \bt{lib} is just a label to the same commit as \bt{master}.
\end{frame}
\begin{frame}
\frametitle{Our example repository}
\includegraphics[width=8cm]{images/example-branched}\\
\vspace{0.5cm}
Created branch \bt{lib} from \bt{master}.
\end{frame}
\begin{frame}[fragile]
\frametitle{Working on a branch: \bt{git commit}}
We can extend the \bt{lib} branch by adding commits.
\bigskip
\begin{lstlisting}
$ echo 'VERSION=1' > testlib.py
$ git add testlib.py
$ git commit -m 'Add empty testlib'
\end{lstlisting}
\pause
\bigskip
\begin{lstlisting}
$ git log --oneline --decorate --graph --all
* 251a51b (HEAD, lib) Add empty testlib
* c7f3bd9 (master) Add .gitignore file
| * 8fc25c1 (interface) Trivial Python interface
|/
* 4a44c4e Merge branch 'license'
|\
| * 0fbe3e3 (license) Add MIT license
...
\end{lstlisting}
\end{frame}
\begin{frame}
\frametitle{Our example repository}
\includegraphics[width=8cm]{images/example-committed}\\
\vspace{0.5cm}
Extended branch \bt{lib}.
\end{frame}
\begin{frame}[fragile]
\frametitle{Fast forward merging: \bt{git merge}}
Let's merge our work on \bt{lib} back into \bt{master}.
\bigskip
\begin{lstlisting}
$ git checkout master
Switched to branch 'master'
$ git merge lib
Updating c7f3bd9..251a51b
Fast-forward
testlib.py | 1 +
1 file changed, 1 insertion(+)
create mode 100644 testlib.py
\end{lstlisting}
\bigskip
This merge was easy:
\begin{itemize}
\item Creates branch \bt{mybranch} at \bt{HEAD}
\item But doesn't switch to it! (use \bt{git checkout})
\item \bt{lib} was directly upstream of \bt{master}.
\item Git just moves \bt{HEAD} and \bt{master} to point to \bt{lib}.
\item This is called a {\em fast forward merge}.
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Our example repository}
\includegraphics[width=8cm]{images/example-merged-ff}\\
\vspace{0.5cm}
Merged branch \bt{lib} into \bt{master} (fast forward).
\end{frame}
\begin{frame}[fragile]
\frametitle{Three-way merging: \bt{git merge}}
Let's merge our work on \bt{interface} back into \bt{master}.
\bigskip
\begin{lstlisting}
$ git merge interface
Merge made by the 'recursive' strategy.
interface.py | 3 +++
1 file changed, 3 insertions(+)
create mode 100755 interface.py
\end{lstlisting}
\bigskip
This merge was harder:
\begin{itemize}
\item \bt{interface} and \bt{master} had diverged.
\item Git determines changes in \bt{interface} and \bt{master} since their
most recent common ancestor and creates a new commit from that.
\item This is called a {\em recursive three-way merge} and the resulting
merge a {\em merge commit}.
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Our example repository}
\includegraphics[width=8cm]{images/example-merged}\\
\vspace{0.5cm}
\includegraphics[width=10cm]{images/branch}
Merged branch \bt{interface} into \bt{master}.
\end{frame}
% todo: merging branches, tags
\begin{frame}[fragile]
\frametitle{Deleting branches: \bt{git branch}}
Old branches that have been merged can be deleted.
\bigskip
\begin{lstlisting}
$ git branch -d interface
Deleted branch interface (was 8fc25c1).
\end{lstlisting}
\bigskip
\begin{lstlisting}
$ git branch -d lib license
Deleted branch lib (was 251a51b).
Deleted branch license (was 0fbe3e3).
\end{lstlisting}
\bigskip
No history is lost, just labels removed.
\end{frame}
% todo: basic merge conflicts, tags
\section{Questions?}
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
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