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

3
\title{Git Basics}
4 5 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
\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.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
\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

  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}
71
\begin{frame}
72 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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 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 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
  \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

  \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 of the changes you made.
  \begin{itemize}
    \item This is useful when you want to search for older versions later.
  \end{itemize}
\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

  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}''.
\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 last commit.]
    $ echo Third version. > README
    $ git diff
    --- a/README
    +++ b/README
    @@ -1 +1 @@
    -First version.
    +Third version.
  \end{lstlisting}
  \bigskip
\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
\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

  \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}
278 279 280 281
\end{frame}

\section{Questions?}
\lastpagetemplate
282
\begin{fframe}
283 284 285 286 287 288 289 290 291 292
  \begin{center}
    Acknowledgements:
    \bigskip
    \bigskip

    Martijn Vermaat

    Zuotian Tatum

  \end{center}
293 294 295 296

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

\end{document}