basics.tex 8.22 KB
Newer Older
1 2
\documentclass[slidestop]{beamer}

3
\title{Git Basics}
4
\providecommand{\myConference}{Git course}
5
\providecommand{\myDate}{Monday, July 7, 2014}
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
\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.
33 34 35 36 37 38 39 40 41 42 43 44 45
\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 <path>/.git/
  \end{lstlisting}
  \bigskip
46
  \pause
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71

  Or you can ``clone'' an existing repository.
  \bigskip

  \begin{lstlisting}[language=none, caption=Clone an existing repository.]
    $ git clone <path-to-repository>
  \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}
72
\begin{frame}
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
  \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
124
  \pause
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148

  \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}

149 150
  This will open an editor, give a short description (50 characters) and a list
  of the changes (72 column format).
151
  \begin{itemize}
152
    \item Useful when you want to search.
153
  \end{itemize}
154 155 156 157 158 159
  \bigskip
  \pause

  \begin{lstlisting}[language=none, caption=Commit a new version.]
    $ git commit -m "Solved the counting bug."
  \end{lstlisting}
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
\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
176
  \pause
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227

  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 <j.f.j.laros@lumc.nl>
    Date:   Fri Oct 11 14:18:13 2013 +0200

        Second version.

    commit 8e10be812fd78f69a5e3bac7670c62438161b6b0
    Author: J.F.J. Laros <j.f.j.laros@lumc.nl>
    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}''.
228 229 230 231 232
  \bigskip
  \pause

  You can also use an unique prefix of this hash, usually six characters is
  enough.
233 234 235 236 237 238 239 240 241
\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
242
    and the staging area.]
243 244 245 246 247 248 249 250 251
    $ echo Third version. > README
    $ git diff
    --- a/README
    +++ b/README
    @@ -1 +1 @@
    -First version.
    +Third version.
  \end{lstlisting}
  \bigskip
252 253 254 255 256 257 258 259 260
  \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}
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
\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
279 280 281 282 283 284
  \pause

  \begin{lstlisting}[language=none, caption=Difference between two committed
    versions.]
    $ git diff 8e10be cc61ee
  \end{lstlisting}
285 286 287 288 289 290 291 292 293
\end{frame}

\section{Extras}
\begin{frame}[fragile]
  \frametitle{Explicit no tracking.}

  Sometimes you do not want to track certain files:
  \begin{itemize}
    \item Executables.
294
    \item \bt{pdf} files (if you still have the \LaTeX\ source).
295 296 297 298
    \item Python bytecode (\bt{.pyc}) files.
    \item Files containing passwords.
  \end{itemize}
  \bigskip
299
  \pause
300

301
  Use the special ``\bt{.gitignore}'' file.
302 303 304 305 306 307 308 309
  \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}
310 311
\end{frame}

312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
\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 <command>
  \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}

332 333
\section{Questions?}
\lastpagetemplate
334
\begin{fframe}
335 336 337 338 339 340 341 342 343
  \begin{center}
    Acknowledgements:
    \bigskip
    \bigskip

    Martijn Vermaat

    Zuotian Tatum

344 345
    Wibowo Arindrarto

346
  \end{center}
347 348 349 350

  \vfill
  \permfoot{http://git-scm.com/book}
\end{fframe}
351 352

\end{document}