Commit bf182669 authored by Jeroen F.J. Laros's avatar Jeroen F.J. Laros

Merge remote-tracking branch 'origin/branching'

parents 24ae7381 5cc09f6f
# Git Introduction Course
# Git introduction course
This course aims at everyone who works in the Bioinformatics field. We cover a
*version control system* named **git**. This system is widely used by software
*version control system* named *Git*. This system is widely used by software
developers, but can also be used for project management. By keeping track of
all versions, history, etc. collaboration with colleagues is easy and your
analysis will be reproducible.
The presentations are made in LaTeX, for the template and stylesheet, go
The presentations are made in *LaTeX*, for the template and stylesheet, go
[here](https://humgenprojects.lumc.nl/svn/presentation/trunk/).
/local/projects/presentation/trunk/Makefile
\ No newline at end of file
/local/projects/presentation/trunk/beamerthemelumc.sty
\ No newline at end of file
\documentclass[slidestop]{beamer}
\title{Working with branches in Git}
\providecommand{\myConference}{Git course}
\providecommand{\myDate}{Monday, October 14, 2013}
\author{Martijn Vermaat}
\providecommand{\myGroup}{Leiden Genome Technology Center}
\providecommand{\myDepartment}{Department of Human Genetics}
\providecommand{\myCenter}{Center for Human and Clinical Genetics}
\providecommand{\lastCenterLogo}{
\raisebox{-0.1cm}{
\includegraphics[height=1cm]{lgtc_logo}
%\includegraphics[height=0.7cm]{ngi_logo}
}
}
\providecommand{\lastRightLogo}{
%\includegraphics[height=0.7cm]{nbic_logo}
%\includegraphics[height=0.8cm]{nwo_logo_en}
%\hspace{1.5cm}\includegraphics[height=0.7cm]{gen2phen_logo}
}
\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.
%\renewcommand{\pause}{}
% Make the title page.
\bodytemplate
\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.
\end{itemize}
\end{frame}
\begin{frame}
\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}.
\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.
\end{itemize}
\vspace{1cm}
\includegraphics[width=10cm]{images/head}
\end{frame}
\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.
\end{itemize}
\vspace{1cm}
\includegraphics[width=10cm]{images/commit}
\end{frame}
\begin{frame}
\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.
\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.
\end{itemize}
\vspace{0.5cm}
\includegraphics[width=6cm]{images/branches}
\end{frame}
\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}.
\end{itemize}
\vspace{0.5cm}
\includegraphics[width=6cm]{images/merge}
\end{frame}
\section{Inspecting the commit graph}
\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}
$ 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 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{Creating a new branch: \bt{git branch}}
\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 \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}
Merged branch \bt{interface} into \bt{master}.
\end{frame}
\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}
\section{Basic merge conflicts}
\begin{frame}
\frametitle{Merge conflicts}
Git is pretty good at merging:
\begin{itemize}
\item The changes might have been in different files.
\item Or in different parts of the same file.
\item Git tries to figure out a sensible result.
\end{itemize}
\pause
\bigskip
Sometimes this is not possible:
\begin{itemize}
\item The changes might be incompatible.
\item When we try \bt{git merge}, Git gives up.
\item This situation is called a {\em merge conflict}.
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Setting the stage (1/3)}
\begin{lstlisting}
$ git log --oneline --decorate --graph --all
* 9d2ad27 (HEAD, master) State character preference
| * 374ab60 (simpsons) State character preference
|/
* 4012f4f Initial commit
\end{lstlisting}
\bigskip
We'd like to merge branch \bt{simpsons} into \bt{master}.
\end{frame}
\begin{frame}[fragile]
\frametitle{Setting the stage (2/3)}
The last commit on \bt{master}:
\bigskip
\begin{lstlisting}
$ git show --oneline
9d2ad27 State character preference
diff --git a/README b/README
index de15194..ef40359 100644
--- a/README
+++ b/README
@@ -1,2 +1,4 @@
Facts about television series
=============================
+
+My favorite character is Eric Cartman.
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Setting the stage (3/3)}
The last commit on \bt{simpsons}:
\bigskip
\begin{lstlisting}
$ git show --oneline simpsons
374ab60 State character preference
diff --git a/README b/README
index de15194..9dd729b 100644
--- a/README
+++ b/README
@@ -1,2 +1,4 @@
Facts about television series
=============================
+
+My favorite character is Homer Simpson.
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Creating a merge conflict}
\begin{lstlisting}
$ git merge simpsons
Auto-merging README
CONFLICT (content): Merge conflict in README
Automatic merge failed; fix conflicts and then
commit the result.
\end{lstlisting}
\bigskip
\begin{lstlisting}
$ git status
# On branch master
# Unmerged paths:
# (use "git add/rm <file>.." as appropriate to
# mark resolution)
#
# both modified: README
#
no changes added to commit (use "git add" and/or
"git commit -a")
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Resolving a merge conflict (1/2)}
\begin{lstlisting}
$ cat README
Facts about television series
=============================
<<<<<<< HEAD
My favorite character is Eric Cartman.
=======
My favorite character is Homer Simpson.
>>>>>>> simpsons
\end{lstlisting}
\bigskip
What we had is under \bt{HEAD}, what \bt{simpsons} had is above
\bt{simpsons}.
\pause
\bigskip
\begin{lstlisting}
$ emacs README
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Resolving a merge conflict (1/2)}
We resolve the conflict by hand.
\bigskip
\begin{lstlisting}
$ cat README
Facts about television series
=============================
My favorite characters are Eric Cartman
and Homer Simpson.
\end{lstlisting}
\pause
\bigskip
And can now finish the merge commit.
\bigskip
\begin{lstlisting}
$ git add README
$ git commit
[master 1e496cb] Merge branch 'simpsons'
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Resolving conflicts with \bt{git mergetool}}
We can also use graphical merge tools such as {\em Meld}.
\bigskip
\begin{lstlisting}
$ git mergetool
merge tool candidates: meld opendiff kdiff3 ...
Merging:
README
Normal merge conflict for 'README':
{local}: modified file
{remote}: modified file
Hit return to start merge resolution tool (meld):
\end{lstlisting}
\end{frame}
\begin{frame}
\frametitle{Meld example}
\includegraphics[width=11cm]{images/meld}\\
\vspace{0.5cm}
Tools like Meld provide an editable three-way diff.
\end{frame}
\section{Questions?}
\lastpagetemplate
\begin{frame}
\begin{center}
Acknowledgements:
\bigskip
\bigskip
Jeroen Laros
Zuotian Tatum
% https://www.atlassian.com/git
\end{center}
\end{frame}
\end{document}
/local/projects/presentation/trunk/gen2phen_logo.eps
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
/local/projects/presentation/trunk/lgtc_logo.eps
\ No newline at end of file
/local/projects/presentation/trunk/lumc_logo.eps
\ No newline at end of file
/local/projects/presentation/trunk/lumc_logo_small.eps
\ No newline at end of file
/local/projects/presentation/trunk/nbic_logo.eps
\ No newline at end of file
/local/projects/presentation/trunk/ngi_logo.eps
\ No newline at end of file
/local/projects/presentation/trunk/nwo_logo_en.eps
\ No newline at end of file
/local/projects/presentation/trunk/ul_logo.eps
\ No newline at end of file
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