\documentclass[slidestop]{beamer} \title{Git Basics} \providecommand{\myConference}{Git course} \providecommand{\myDate}{Monday, October 14, 2013} \author{Jeroen F. J. Laros} \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} \begin{document} % This disables the \pause command, handy in the editing phase. %\renewcommand{\pause}{} % Make the title page. \bodytemplate % First page of the presentation. \section{Initialisation} \begin{frame}[fragile] \frametitle{Starting a project.} Creating a new repository is easy. You do not need a server, no registration, etc. \bigskip \begin{lstlisting}[language=none, caption=Make a new repository.] $ git init Initialized empty Git repository in /.git/ \end{lstlisting} \bigskip \pause Or you can ``clone'' an existing repository. \bigskip \begin{lstlisting}[language=none, caption=Clone an existing repository.] $ git clone \end{lstlisting} \end{frame} \begin{frame}[fragile] \frametitle{Starting a project.} You can see a hidden directory in a Git repository. \bigskip \begin{lstlisting}[language=none, caption=A hidden directory is added.] $ ls -a . .. .git \end{lstlisting} \bigskip This directory contains almost everything that Git stores and manipulates. \end{frame} \section{Manipulation} \begin{frame} \frametitle{Local operations.} \begin{figure}[] \begin{center} \includegraphics[height=0.8\textheight]{pics/18333fig0106-tn} \end{center} \caption{Working directory, staging area, and Git directory.} \label{} \end{figure} \end{frame} \begin{frame}[fragile] \frametitle{Checking the status of your files.} \begin{lstlisting}[language=none, caption=Check status.] $ git status nothing to commit (working directory clean) \end{lstlisting} \bigskip ``\bt{git status}'' can tell you whether your files are: \begin{itemize} \item Untracked. \item Unmodified. \item Modified. \item Staged. \end{itemize} \end{frame} \begin{frame} \frametitle{Checking the status of your files.} \begin{figure}[] \begin{center} \includegraphics[height=0.8\textheight]{pics/18333fig0201-tn} \end{center} \caption{The lifecycle of the status of your files.} \label{} \end{figure} \end{frame} \begin{frame}[fragile] \frametitle{Adding, removing, renaming.} \begin{lstlisting}[language=none, caption=This file is not tracked.] $ echo First version. > README $ git status # Untracked files: # README \end{lstlisting} \bigskip \pause \begin{lstlisting}[language=none, caption=Now the file will be tracked.] $ git add README $ git status # Changes to be committed: # new file: README \end{lstlisting} \bigskip To rename a file, use ``\bt{git mv}'', to remove, use ``\bt{git rm}''. \end{frame} \section{Working with versions} \begin{frame}[fragile] \frametitle{commit} Once you have modified your files and added them to the \emph{staging area}, you can commit them (add them to the repository). \bigskip \begin{lstlisting}[language=none, caption=Commit a new version.] $ git commit \end{lstlisting} This will open an editor, give a short description (50 characters) and a list of the changes (72 column format). \begin{itemize} \item Useful when you want to search. \end{itemize} \bigskip \pause \begin{lstlisting}[language=none, caption=Commit a new version.] $ git commit -m "Solved the counting bug." \end{lstlisting} \end{frame} \begin{frame}[fragile] \frametitle{Undoing changes.} Sometimes you will accidentally add a file. \bigskip \begin{lstlisting}[language=none, caption=Adding a new version of a file.] $ echo Second version. > README $ git add README $ git status # Changes to be committed: # modified: README \end{lstlisting} \bigskip \pause If you want to undo this, you can use ``\bt{git reset}''. \bigskip \begin{lstlisting}[language=none, caption=Unstage a file.] $ git reset README $ git status # Changes not staged for commit: # modified: README \end{lstlisting} \end{frame} \begin{frame}[fragile] \frametitle{Viewing the history.} To see the history of your project, use ``\bt{git log}''. \bigskip \begin{lstlisting}[language=none, caption=The log of our project.] $ git add README $ git commit $ git log commit cc61ee7cd72590f3bebcc9e1ff3e9435c7f7dd28 Author: J.F.J. Laros Date: Fri Oct 11 14:18:13 2013 +0200 Second version. commit 8e10be812fd78f69a5e3bac7670c62438161b6b0 Author: J.F.J. Laros Date: Fri Oct 11 14:17:51 2013 +0200 First version. \end{lstlisting} \end{frame} \begin{frame}[fragile] \frametitle{Undo a commit.} Sometimes we want to undo an entire commit. This is done with ``\bt{git revert}''. \bigskip \begin{lstlisting}[language=none, caption=Revert a commit.] $ git revert cc61ee7cd72590f3bebcc9e1ff3e9435c7f7dd28 $ cat README First version. \end{lstlisting} \bigskip The hash can be found with ``\bt{git log}''. \bigskip \pause You can also use an unique prefix of this hash, usually six characters is enough. \end{frame} \begin{frame}[fragile] \frametitle{Viewing changes in detail.} If you want to see what has changed, use ``\bt{git diff}''. \bigskip \begin{lstlisting}[language=none, caption=Difference between the working copy and the staging area.] $ echo Third version. > README $ git diff --- a/README +++ b/README @@ -1 +1 @@ -First version. +Third version. \end{lstlisting} \bigskip \pause For staged files, use the ``\bt{--cached}'' or ``\bt{--staged}'' option. \bigskip \begin{lstlisting}[language=none, caption=Difference between the staging area and the last commit.] $ git diff --cached \end{lstlisting} \end{frame} \begin{frame}[fragile] \frametitle{Viewing changes in detail.} You can see the differences between any two versions. \bigskip \begin{lstlisting}[language=none, caption=Difference between the working copy and an other commit.] $ git diff cc61ee --- a/README +++ b/README @@ -1 +1 @@ -Second version. +Third version. \end{lstlisting} \bigskip \pause \begin{lstlisting}[language=none, caption=Difference between two committed versions.] $ git diff 8e10be cc61ee \end{lstlisting} \end{frame} \section{Extras} \begin{frame}[fragile] \frametitle{Explicit no tracking.} Sometimes you do not want to track certain files: \begin{itemize} \item Executables. \item \bt{pdf} files (if you still have the \LaTeX\ source). \item Python bytecode (\bt{.pyc}) files. \item Files containing passwords. \end{itemize} \bigskip \pause Use the special ``\bt{.gitignore}'' file. \begin{lstlisting}[language=none, caption=Ignoring certain files.] $ touch notrack.txt $ echo notrack.txt > .gitignore $ git add .gitignore $ git commit $ git status nothing to commit, working directory clean \end{lstlisting} \end{frame} \begin{frame}[fragile] \frametitle{Help.} With the ``\bt{help}'' command get the manual of a particular subcommand. \bigskip \begin{lstlisting}[language=none, caption=Get the full manual.] $ git help \end{lstlisting} \bigskip \pause Example. \bigskip \begin{lstlisting}[language=none, caption=Get the manual for the diff subcommand.] $ git help diff \end{lstlisting} \end{frame} \section{Questions?} \lastpagetemplate \begin{fframe} \begin{center} Acknowledgements: \bigskip \bigskip Martijn Vermaat Zuotian Tatum \end{center} \vfill \permfoot{http://git-scm.com/book} \end{fframe} \end{document}