basics.tex 8.2 KB
Newer Older
Laros's avatar
Laros committed
1
2
\documentclass[slidestop]{beamer}

3
\title{Git Basics}
Laros's avatar
Laros committed
4
\providecommand{\myConference}{Git course}
5
\providecommand{\myDate}{Monday, July 7, 2014}
Laros's avatar
Laros committed
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
\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.]
42
    $ cd ~/projects
43
44
45
46
    $ git init
    Initialized empty Git repository in <path>/.git/
  \end{lstlisting}
  \bigskip
Laros's avatar
Laros committed
47
  \pause
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72

  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}
Laros's avatar
Laros committed
73
\begin{frame}
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
  \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
Laros's avatar
Laros committed
125
  \pause
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149

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

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

  \begin{lstlisting}[language=none, caption=Commit a new version.]
    $ git commit -m "Solved the counting bug."
  \end{lstlisting}
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
\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
Laros's avatar
Laros committed
177
  \pause
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

  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 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}''.
Laros's avatar
Laros committed
227
228
229
  \bigskip
  \pause

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

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

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

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

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

Laros's avatar
Laros committed
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
\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}

Laros's avatar
Laros committed
331
332
\section{Questions?}
\lastpagetemplate
333
\begin{fframe}
Laros's avatar
Laros committed
334
335
336
337
338
339
340
341
342
  \begin{center}
    Acknowledgements:
    \bigskip
    \bigskip

    Martijn Vermaat

    Zuotian Tatum

343
344
    Wibowo Arindrarto

Laros's avatar
Laros committed
345
  \end{center}
346
347
348
349

  \vfill
  \permfoot{http://git-scm.com/book}
\end{fframe}
Laros's avatar
Laros committed
350
351

\end{document}