Final release
[ai-gitflashtalk.git] / git.tex
1 %&preamble
2 \begin{document}
3
4 \frame{\titlepage}
5
6 \begin{frame}
7 \frametitle{Table of contents}
8 \tableofcontents
9 \end{frame}
10
11 \section{Introduction}
12 \begin{frame}
13 \frametitle{Who am I?}
14 \begin{itemize}
15 \item Mart Lubbers
16 \item 4th year bachelor AI
17 \item \url{https://github.com/dopefishh/gitflashtalk}
18 \item SHA of the commit of this presentation:
19 {\tiny\GITAbrHash}
20 \end{itemize}
21 \end{frame}
22
23 \begin{frame}
24 \frametitle{Where did GIT come from?}
25 \begin{block}{History}
26 \begin{columns} \column{0.4\linewidth}
27 \begin{itemize}
28 \item Pronounce: \textipa{[g\'\i t]}
29 \item Linus Thorvalds
30 \item Linux kernel
31 \end{itemize}
32
33 \column{0.5\linewidth}
34 \begin{figure}[H]
35 \centering
36 \includegraphics[width=0.5\linewidth]{1.png}
37 \caption{Linus Torvalds}
38 \end{figure}
39 \end{columns}
40 \end{block}
41
42 \begin{block}{What is GIT?}
43 \begin{itemize}
44 \item Version control
45 \end{itemize}
46 \end{block}
47 \end{frame}
48
49 \begin{frame}
50 \frametitle{Why GIT?}
51 \begin{block}{Pros}
52 \begin{itemize}
53 \item Fast
54 \item Scaleable
55 \item Simple
56 \item Support for non linear development
57 \item Intermediate stage between committing and pushing
58 \end{itemize}
59 \end{block}
60
61 \begin{block}{Cons}
62 \begin{itemize}
63 \item Binary files
64 \item Intermediate stage between committing and pushing
65 \end{itemize}
66 \end{block}
67 \end{frame}
68
69 \section{Installation}
70 \begin{frame}[fragile]
71 \begin{block}{{\Large\Smiley\Smiley} Linux}
72 Depending on the distribution you may have to do:\\
73 \texttt{\# apt-get install git}\\
74 \texttt{\# pacman -S git}\\
75 \texttt{\# yum install git}\\
76 \texttt{\# emerge --ask dev-vcs/git}\\
77 Etc\ldots
78 \end{block}
79
80 \begin{block}{{\Large\Frowny\Smiley} Mac}
81 Install via XCode tools. Just run \lstinline{$\$$ git} and
82 when GIT is not installed it will prompt you with instructions.
83 \end{block}
84
85 \begin{block}{{\Large\Frowny\Frowny} Windows}
86 Downoad the binary from \url{http://git-scm.com/download/win} and install.
87 \end{block}
88
89 \end{frame}
90
91 \section{Getting started \& workflow}
92 \begin{frame}[fragile]
93 \frametitle{Getting started}
94 \begin{block}{Check GIT version in (GIT) bash}
95 \begin{lstlisting}
96 frobnicator@frobmachine:~$\$$ git --version
97 git version 1.7.10.4
98 \end{lstlisting}
99 \end{block}
100
101 \begin{block}{Create a repository}
102 \begin{lstlisting}
103 frobnicator@frobmachine:~/projects$\$$ git init myfirstproject
104 Initialized empty Git repository in /home/frobnicator/projects/myfirstproject/.git/
105
106 frobnicator@frobmachine:~/projects$\$$ ls -1 myfirstproject/.git
107 branches/
108 config
109 description
110 HEAD
111 hooks/
112 info/
113 objects/
114 refs/
115 \end{lstlisting}
116 \end{block}
117 \end{frame}
118
119 \begin{frame}
120 \frametitle{Four (five) stages}
121 \begin{itemize}
122 \item (Stash)
123 \item Workspace
124 \item Index
125 \item Local repo
126 \item Upstream repo
127 \end{itemize}
128 \end{frame}
129
130 \begin{frame}
131 \frametitle{Workflow}
132 \begin{figure}[H]
133 \centering
134 \includegraphics[scale=0.4]{2.png}
135 \caption{Git workflow}
136 \end{figure}
137 \end{frame}
138
139 \section{Everything is a commit}
140 \begin{frame}[fragile]
141 \frametitle{Add and commit}
142 \begin{lstlisting}
143 frobnicator@frobmachine:~/projects/myfirstproject$\$$ echo "This is a frobfile" > frobbedfile
144
145 frobnicator@frobmachine:~/projects/myfirstproject$\$$ git status
146 On branch master
147
148 Initial commit
149
150 Untracked files:
151 (use "git add <file>..." to include in what will be committed)
152
153 frobbedfile
154
155 nothing added to commit but untracked files present (use "git add" to track)
156 \end{lstlisting}
157 \end{frame}
158
159 \begin{frame}[fragile]
160 \begin{lstlisting}
161 frobnicator@frobmachine:~/projects/myfirstproject$\$$ git add frobbedfile
162
163 frobnicator@frobmachine:~/projects/myfirstproject$\$$ git status
164 On branch master
165
166 Initial commit
167
168 Changes to be committed:
169 (use "git rm --cached <file>..." to unstage)
170
171 new file: frobbedfile
172
173 frobnicator@frobmachine:~/projects/myfirstproject$\$$ git commit
174 [master (root-commit) 2b7355e] Adds frobbedfile
175 1 file changed, 1 insertion(+)
176 create mode 100644 frobbedfile
177 \end{lstlisting}
178 \end{frame}
179
180 \begin{frame}[fragile]
181 \frametitle{Log \& Checkout}
182 \begin{lstlisting}
183 frobnicator@frobmachine:~/projects/myfirstproject$\$$ echo "This is a second frobbedfile" > frob2
184 frobnicator@frobmachine:~/projects/myfirstproject$\$$ git add frob2
185 frobnicator@frobmachine:~/projects/myfirstproject$\$$ git commit -m "This is a second commit"
186 [master cd094bc] This is a second commit
187 1 file changed, 1 insertion(+)
188 create mode 100644 frob2
189 \end{lstlisting}
190 \end{frame}
191
192 \begin{frame}[fragile]
193 \frametitle{Log \& Checkout 2}
194 \begin{lstlisting}
195 frobnicator@frobmachine:~/projects/myfirstproject$\$$ git log
196 commit cd094bc6b81812256533395454db22da07d1e5a4
197 Author: Frob Nicator <frob@nicator.net>
198 Date: Thu Apr 16 22:44:42 2015 +0200
199
200 This is a second commit
201
202 commit c9c9b358cddcbee541ec433a2dc2d5ffe3e928c2
203 Author: Frob Nicator <frob@nicator>
204 Date: Thu Apr 16 22:44:42 2015 +0200
205
206 Adds frobbedfile
207 frobnicator@frobmachine:~/projects/myfirstproject$\$$ ls
208 frob2 frobbedfile
209 \end{lstlisting}
210 \end{frame}
211
212 \begin{frame}[fragile]
213 \frametitle{Log \& Checkout 2}
214 \begin{lstlisting}
215 frobnicator@frobmachine:~/projects/myfirstproject$\$$ git checkout c9c9b3
216 Note: checking out 'c9c9b3'.
217
218 You are in 'detached HEAD' state. You can look around, make experimental
219 changes and commit them, and you can discard any commits you make in this
220 state without impacting any branches by performing another checkout.
221
222 If you want to create a new branch to retain commits you create, you may
223 do so (now or later) by using -b with the checkout command again. Example:
224
225 git checkout -b new_branch_name
226
227 HEAD is now at c9c9b35... Adds frobbedfile
228 frobnicator@frobmachine:~/projects/myfirstproject$\$$ ls
229 frobbedfile
230 \end{lstlisting}
231 \end{frame}
232
233 \begin{frame}[fragile]
234 \frametitle{Log \& Checkout 3}
235 \framesubtitle{We lost our commit and our file!}
236 \begin{lstlisting}
237 frobnicator@frobmachine:~/projects/myfirstproject$\$$ git log
238 commit c9c9b358cddcbee541ec433a2dc2d5ffe3e928c2
239 Author: Frob Nicator <frob@nicator>
240 Date: Thu Apr 16 22:44:42 2015 +0200
241
242 Adds frobbedfile
243 frobnicator@frobmachine:~/projects/myfirstproject$\$$ ls
244 frobbedfile
245 \end{lstlisting}
246 \end{frame}
247
248 \begin{frame}[fragile]
249 \frametitle{Log \& Checkout 4}
250 \begin{block}{Ofcourse not, you never lose stuff with git}
251 \begin{lstlisting}
252 frobnicator@frobmachine:~/projects/myfirstproject$\$$ git log --all
253 commit cd094bc6b81812256533395454db22da07d1e5a4
254 Author: Frob Nicator <frob@nicator.net>
255 Date: Thu Apr 16 22:44:42 2015 +0200
256
257 This is a second commit
258 ...
259 ...
260 \end{lstlisting}
261 \end{block}
262 \end{frame}
263
264 \begin{frame}[fragile]
265 \frametitle{Log \& Checkout 5}
266 \begin{block}{We can just checkout the hash again}
267 \begin{lstlisting}
268 frobnicator@frobmachine:~/projects/myfirstproject$\$$ ls
269 frob2 frobbedfile
270 frobnicator@frobmachine:~/projects/myfirstproject$\$$ git log --decorate --oneline --graph --all
271 * cd094bc (HEAD, master) This is a second commit
272 * c9c9b35 Adds frobbedfile
273 \end{lstlisting}
274 \end{block}
275 \end{frame}
276
277
278 \section{Branching and unevitable merging}
279 \begin{frame}
280 \frametitle{Branching}
281 \begin{itemize}
282 \item Commit: State of the folder. Has and knows his parent.\\
283 \item Branch: Just a named commit.\\
284 Usually a sidetrack of a project.\\
285 Master, develop, feature, etc\ldots
286 \item Tag: Just a named commit.\\
287 Usually marked point to jump to later on.\\
288 eg. Version release, big change etc\ldots
289 \end{itemize}
290 \end{frame}
291
292 \begin{frame}[fragile]
293 \frametitle{Branching 2}
294 \begin{block}{See current branch}
295 \begin{lstlisting}
296 frobnicator@frobmachine:~/projects/myfirstproject$\$$ git branch
297 * master
298 \end{lstlisting}
299 \end{block}
300 \begin{block}{Create new branch}
301 \begin{lstlisting}
302 frobnicator@frobmachine:~/projects/myfirstproject$\$$ git checkout -b "develop"
303 Switched to a new branch 'develop'
304 frobnicator@frobmachine:~/projects/myfirstproject$\$$ git branch
305 * develop
306 master
307 \end{lstlisting}
308 \end{block}
309 \begin{block}{Delete branch}
310 \begin{lstlisting}
311 frobnicator@frobmachine:~/projects/myfirstproject$\$$ git branch -d "develop"
312 Deleted branch develop (was cd094bc).
313 frobnicator@frobmachine:~/projects/myfirstproject$\$$ git branch
314 * master
315 \end{lstlisting}
316 \end{block}
317 \end{frame}
318
319 \begin{frame}[fragile]
320 \frametitle{Push \& Pull}
321 \begin{block}{What?}
322 \begin{itemize}
323 \item Push your changes upsteam repository (eg.\ github)
324 \item Pull their changes from upstream
325 \item Merge into your branch
326 \end{itemize}
327 \end{block}
328 \begin{block}{How?}
329 \begin{lstlisting}
330 frobnicator@frobmachine:~/projects/myfirstproject$\$$ git remote add origin https://github.com/dopefishh/prj.git
331 frobnicator@frobmachine:~/projects/myfirstproject$\$$ git push origin master
332 frobnicator@frobmachine:~/projects/myfirstproject$\$$ git pull origin master
333 \end{lstlisting}
334 \end{block}
335 \end{frame}
336
337 \begin{frame}[fragile]
338 \frametitle{Merge}
339 \begin{block}{Merge develop to master}
340 \begin{lstlisting}
341 frobnicator@frobmachine:~/projects/myfirstproject$\$$ git merge develop
342 \end{lstlisting}
343 \end{block}
344
345 \begin{block}{How to get a conflict}
346 \begin{itemize}
347 \item We make a file with three lines
348 \item On every line we set: \texttt{regelN} where N is line
349 number.
350 \item Change line 2 in the master and develop branch to a
351 separate thing.
352 \item Commit both and checkout master
353 \item Do merge
354 \end{itemize}
355 \end{block}
356 \end{frame}
357
358 \begin{frame}[fragile]
359 \frametitle{Merge 2}
360 \begin{block}{Merge message}
361 \begin{lstlisting}
362 frobnicator@frobmachine~/projects/myfirstproject$\$$ git merge develop
363 Auto-merging mergeconfict
364 CONFLICT (content): Merge conflict in mergeconfict
365 Automatic merge failed; fix conflicts and then commit the result.
366 \end{lstlisting}
367 \end{block}
368 \begin{block}{Contents of mergeconflict file}
369 \begin{lstlisting}
370 1 regel1
371 2 <<<<<<< HEAD
372 3 masterregel2
373 4 =======
374 5 developregel2
375 6 >>>>>>> develop
376 7 regel3
377 \end{lstlisting}
378 \end{block}
379 \end{frame}
380
381 \begin{frame}[fragile]
382 \frametitle{Merge 3}
383 \begin{block}{Commit message}
384 \begin{lstlisting}
385 1 Merge branch 'develop'
386 2
387 3 Conflicts:
388 4 mergeconfict
389 5 #
390 6 # It looks like you may be committing a merge.
391 7 # If this is not correct, please remove the file
392 8 # .git/MERGE_HEAD
393 9 # and try again.
394 10
395 11
396 12 # Please enter the commit message for your changes. Lines starting
397 13 # with '#' will be ignored, and an empty message aborts the commit.
398 14 # On branch master
399 15 # All conflicts fixed but you are still merging.
400 16 #
401 17 # Changes to be committed:
402 18 # modified: mergeconfict
403 19 #
404 \end{lstlisting}
405 \end{block}
406 \end{frame}
407
408 \begin{frame}[fragile]
409 \frametitle{Merge 4}
410 \begin{block}{Output from git log}
411 \begin{lstlisting}
412 * a6474c9 (HEAD, master) Merge branch 'develop'
413 |\
414 | * 8b292ad (develop) Develop merge conflict
415 * | 7d5018a Master merge confict
416 |/
417 * 885a341 First merge conflict push
418 * cd094bc This is a second commit
419 * c9c9b35 Adds frobbedfile
420 \end{lstlisting}
421 \end{block}
422 \end{frame}
423
424 \section{Tips \& Tricks}
425 \begin{frame}[fragile]
426 \frametitle{\texttt{/home/frobnicator/.gitconfig}}
427 \begin{lstlisting}
428 frobnicator@frobmachine~$\$$ cat .gitconfig
429 [user]
430 name = Frob Nicator
431 email = frob@nicator.com
432
433 [alias]
434 tree = log --decorate --oneline --graph --all
435 pushm = push origin master
436 pushd = push origin develop
437 \end{lstlisting}
438 \end{frame}
439
440 \begin{frame}[fragile]
441 \frametitle{Public key}
442 \begin{block}{SSH config}
443 \begin{lstlisting}
444 frobnicator@frobmachine:~$\$$ cat .ssh/config
445 Host github.com
446 IdentityFile /home/frobnicator/.ssh/github
447 User git
448 \end{lstlisting}
449 \end{block}
450 \begin{block}{Create Key}
451 \begin{lstlisting}
452 frobnicator@frobmachine:~ $\$$ ssh-keygen -f /home/frobnicator/.ssh/github
453 \end{lstlisting}
454 \end{block}
455 \begin{block}{Clone with ssh}
456 \begin{lstlisting}
457 frobnicator@frobmachine:~/projects/myfirstproject$\$$ git remote add origin git@github.com:frobnicator/prj.git
458 frobnicator@frobmachine:~/projects/$\$$ git clone git@github.com:frobnicator/prj.git
459 \end{lstlisting}
460 \end{block}
461 \end{frame}
462
463 \begin{frame}
464 \frametitle{Any questions?}
465 This presentation can be found on:\\
466 \url{https://github.com/dopefishh/gitflashtalk}
467 \end{frame}
468
469 \end{document}