summaryrefslogtreecommitdiff
path: root/application-devel/git/frm_git_basics.tex
blob: e23966c1369a2c780f0ab0a3e2eb2d7a5d1b9632 (plain)
1
2
3
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
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
71
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
% ----------------------------
\subsubsection{Git Basics}

% ----------------------------
\begin{frame}[fragile]{What is Git?}
\begin{itemize}
\item Version Control System (VCS)
\item Snapshot Store (no Diffs)
\item Fully Distributed
\item Full local History
\item Optimized for Non-linear Development
\item Measured Code Integrity (Merkle-Tree)
\end{itemize}
\end{frame}

% ----------------------------
\begin{frame}[fragile]{Components I}
\begin{itemize}
\item Working Tree
 \begin{itemize}
 \item All Files of a Snapshot
 \item Checkout of a Commit History (Branch, Tag, detached)
 \end{itemize}
\item Staging Area
 \begin{itemize}
 \item Preparation for Commit
 \item Workingtree -> Staging Area -> Commit
 \end{itemize}
\item Commit
 \begin{itemize}
 \item ID: Unique Identifier
 \item Changeset with Description
 \end{itemize}
\item Branch
 \begin{itemize}
 \item Local: Separate List of Commits
 \item Remote: Pointer to a Commit
 \end{itemize}
\end{itemize}
\end{frame}

% ----------------------------
\begin{frame}[fragile]{Components II}
\begin{itemize}
\item Tags
 \begin{itemize}
 \item Reference to a Commit ID
 \item annotated: with own description
 \end{itemize}
\item Objects
 \begin{itemize}
 \item Storage Containers
 \item Hashed Versions of Files
 \end{itemize}
\item HEAD
 \begin{itemize}
 \item Pointer to Top-Level Commit of Branch or Workingtree
 \end{itemize}
\item Stash
 \begin{itemize}
 \item Store for non-committed Changes
 \end{itemize}
\end{itemize}
\end{frame}

% ----------------------------
\begin{frame}[fragile]{Collaboration}
\begin{itemize}
\item Pull/Push Changes from/to other Repositories
\item between local User Repositories (file-system)
\item Web-server based Repositories (read-only)
\item User Access Control (e.g. with git or ssh)
\item Protocols
 \begin{itemize}
 \item \texttt{file://}
 \item \texttt{http://}
 \item \texttt{https://}
 \item \texttt{git://}
 \item \texttt{ssh://}
 \item etc.
 \end{itemize}
\end{itemize}
\end{frame}

% ----------------------------
\begin{frame}[fragile]{File States in Workingtree}
\begin{figure}[h]
\centering
\includegraphics[width=8cm]{images/git_file_states.png}
\end{figure}
\end{frame}

% ----------------------------
\subsubsection{Best Practice}

% ----------------------------
\begin{frame}[fragile]{Best Practice}
\begin{itemize}
\item use Local Repositories (keep track also for small, local projects)
\item commit Functional Changes
\item Split Commits into separate, functional Entities
\item Separate Branch for Feature
\item Push frequently to Remote Repositories
\item Write significant Commit Messages
 \begin{itemize}
 \item Problem/Motivation
 \item Problem Context
 \item Fix/Feature Description
 \item use Commit ID to refer to other Commits
 \end{itemize}
\end{itemize}
\end{frame}

% ----------------------------
\begin{frame}[fragile]{Bad Commit Messages}
\begin{itemize}
\item Non-existing Commit Message
\item Mix Functional Changes
\end{itemize}
\begin{beamerboxesrounded}[shadow=true]{Bad Example I}
\begin{scriptsize}
\begin{verbatim}
commit 009e0d048028f2265555aeb1575b495f0cb4da9c
Author: Holger Dengler <dengler@linutronix.de>
Date:   Mon Feb 26 13:00:00 2018 +0100

    fix
\end{verbatim}
\end{scriptsize}
\end{beamerboxesrounded}
\begin{beamerboxesrounded}[shadow=true]{Bad Example II}
\begin{scriptsize}
\begin{verbatim}
commit 8ca31a793d9805a12304f85ae0a063e4c7dac4b0
Author: root <root@build.local>
Date:   Fri Feb 23 16:00:00 2018 +0100

    Various fixes of this week, still work in progress. TGIF and
    have a nice weekend!

\end{verbatim}
\end{scriptsize}
\end{beamerboxesrounded}
\end{frame}

% ----------------------------
\begin{frame}[fragile]{Better Commit Messages}
\begin{beamerboxesrounded}[shadow=true]{Bad Example}
\begin{scriptsize}
\begin{verbatim}
commit 03f5942e8d9ae7bad608a9bcda8067f2f40f7840 (HEAD -> master)
Author: Holger Dengler <dengler@linutronix.de>
Date:   Mon Feb 26 13:00:00 2018 +0100

    Initialize the XYZ Control Register with 0x15. This resolves the hang
    during boot on my device.
\end{verbatim}
\end{scriptsize}
\end{beamerboxesrounded}
\begin{beamerboxesrounded}[shadow=true]{Better Example}
\begin{scriptsize}
\begin{verbatim}
commit 7de69687544549cc2e077663a1e58f05b91d6990 (HEAD -> master)
Author: Holger Dengler <dengler@linutronix.de>
Date:   Mon Feb 26 13:00:00 2018 +0100

    imx: Initialize XYZ_CTRL during device probe

    After a warm reboot, the control register of the XYZ Component is not
    set to the correct reset values, as described in the Reference
    Manual. This causes non-deterministic race conditions during the probe
    of the device.

    Setting the control register to the power-on reset values triggers an
    internal reset of the component. The device can be probed in a proper
    way in all reboot cases (POR and warm reset).

    See: Reference Manual, Page 4711, XYZ Device Initialization and
    Control Register.

    Signed-off-by: Holger Dengler <dengler@linutronix.de>
\end{verbatim}
\end{scriptsize}
\end{beamerboxesrounded}
\end{frame}

% ----------------------------
\subsubsection{Working with local Git Repositories}

% ----------------------------
\begin{frame}[fragile]{Create an empty Repository}
\begin{itemize}
\item Create a top-level Directory
\item Initialize the Repository Configuration and History
\end{itemize}
\begin{beamerboxesrounded}[shadow=true]{Example: Create empty Repository}
\begin{scriptsize}
\begin{verbatim}
# Create top-level Directory of Repo
mkdir myrepo

# Initialize Repository
cd ./myrepo
git init

# opt.: Initialize Repository without Workingtree
git init --bare
\end{verbatim}
\end{scriptsize}
\end{beamerboxesrounded}
\end{frame}

% ----------------------------
\begin{frame}[fragile]{Git Configuration}
\begin{itemize}
\item System-wide Configuration (Scope of Distribution)
\item Global Configuration (Defaults for all Repositories of a User)
 \begin{itemize}
 \item Location: \texttt{\~{}/.gitconfig}
 \end{itemize}
\item Local Configuration (Repository-local)
 \begin{itemize}
 \item Location: \texttt{<repo-dir>/.git/config}
 \end{itemize}
\end{itemize}
\begin{beamerboxesrounded}[shadow=true]{Example: Configure Git}
\begin{scriptsize}
\begin{verbatim}
# Set Name and E-Mails address of the User
git config --global --add user.name "Jo Developer"
git config --global --add user.email "devel@acme.com"
git config --global --add core.editor "pluma"

# Other E-Mail address for some Repositories
cd <repo-dir>
git config --local --add user.email "devel@private-mail.eu"
\end{verbatim}
\end{scriptsize}
\end{beamerboxesrounded}
\end{frame}

% ----------------------------
\begin{frame}[fragile]{Add/Change Files}
\begin{itemize}
\item Create (or edit) Files
\item Check Changes
\item Stage Changes
\item Commit Changes
\end{itemize}
\begin{beamerboxesrounded}[shadow=true]{Example: Add File to Repository}
\begin{scriptsize}
\begin{verbatim}
# Add or Edit Files
echo "hello world" > myfile

# Check unstaged Changes
git status
git diff

# Stage Changes
git add myfile

# Check staged Changes
git status
git diff --cached

# Commit staged Changes (opens editor for the commit message)
git commit -s
\end{verbatim}
\end{scriptsize}
\end{beamerboxesrounded}
\end{frame}

% ----------------------------
\begin{frame}[fragile]{Cleanup}
\begin{itemize}
\item Clean untracked Files
\item Reset unstaged Changes (reset to Repository Version)
\item Remove Files from Stage Area (reset to unstaged State)
\end{itemize}
\begin{beamerboxesrounded}[shadow=true]{Examples: Cleanup}
\begin{scriptsize}
\begin{verbatim}
# Delete untracked Files
git clean

# Rollback File Changes
git checkout -- path/to/file

# Remove File from Stage Area
git reset HEAD path/to/file
\end{verbatim}
\end{scriptsize}
\end{beamerboxesrounded}
\end{frame}

% ----------------------------
\begin{frame}[fragile]{Exclude Files from Version Tracking}
\begin{itemize}
\item List of ignored Files (~/.gitignore)
\item specific List for each Directory possible
\item allow Wildcards
\item Wildcard Exceptions starts with "!"
\end{itemize}
\begin{beamerboxesrounded}[shadow=true]{Example: Ignore List}
\begin{scriptsize}
\begin{verbatim}
# Fill Ignore List
cat > .gitignore << EOF
.*
!.gitignore
*.o
*.exe
EOF

# Check Status
git status

# Commit intial Ignore List
git add .gitignore
gitcommit -s -m "Initial Repository Ignore List"
\end{verbatim}
\end{scriptsize}
\end{beamerboxesrounded}
\end{frame}

% ----------------------------
\begin{frame}[fragile]{Branches}
\begin{itemize}
\item Create new Branch from:
 \begin{itemize}
 \item Commit (ID)
 \item Tag
 \item existing Branch
 \end{itemize}
\end{itemize}
\begin{beamerboxesrounded}[shadow=true]{Example: Branches}
\begin{scriptsize}
\begin{verbatim}
# Create a new Branch (no changes to Workingtree)
git branch <branch-name> [<commit/branch/tag>]

# Create a new Branch and checkout to Workingtree
git checkout -b <new-branch> [<commit/branch/tag>]
\end{verbatim}
\end{scriptsize}
\end{beamerboxesrounded}
\end{frame}

% ----------------------------
\subsubsection{Working with Remote Git Repositories}

% ----------------------------
\begin{frame}[fragile]{Clone Repository}
\begin{itemize}
\item Clone a Remote Repository
\item Creates a local Clone (Copy) of another Repository (with complete
History)
\end{itemize}
\begin{beamerboxesrounded}[shadow=true]{Example: Clone Repository}
\begin{scriptsize}
\begin{verbatim}
# Clone Linux Kernel Repository from Github
git clone https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

# check content
cd linux
ls -l
git log

# Clone Linux Kernel Repository from Github without Workingtree
git clone --bare https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

# no Checkouts, but History is available
cd linux.git
ls -l
git log
\end{verbatim}
\end{scriptsize}
\end{beamerboxesrounded}
\end{frame}

% ----------------------------
\begin{frame}[fragile]{Add Remote Repositories}
\begin{itemize}
\item multiple Remotes possible
\item e.g.: Pull from Development- and push to Release-Repository
\end{itemize}
\begin{beamerboxesrounded}[shadow=true]{Examples: Remote}
\begin{scriptsize}
\begin{verbatim}
# Check all Remotes (with URL)
git remote -v

# Add a new Remote
git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
\end{verbatim}
\end{scriptsize}
\end{beamerboxesrounded}
\end{frame}

% ----------------------------
\begin{frame}[fragile]{Synchronize/Get Changes from Remote}
\begin{itemize}
\item Fetch: update Repository History
\item Pull: update Repository and Workingtree
\end{itemize}
\begin{beamerboxesrounded}[shadow=true]{Examples: Fetch/Pull}
\begin{scriptsize}
\begin{verbatim}
# update History from Maniline Repository
git fetch linus

# Update History of all Remote Repositories
git fetch --all

# Synchronize the local master Workingtree with master Branch
# of Remote "linus"
git checkout master
git pull linus master
\end{verbatim}
\end{scriptsize}
\end{beamerboxesrounded}
\end{frame}

% ----------------------------
\begin{frame}[fragile]{Synchronize/Put Changes to Remote}
\begin{itemize}
\item Push Changes to another Repository
\item Requires Write-Access
\end{itemize}
\begin{beamerboxesrounded}[shadow=true]{Examples: Push}
\begin{scriptsize}
\begin{verbatim}
# Prepare the Push-Branch
git checkout -b release-v1.0 master

# Pull from Development Repository
git pull devel-repo prepare_master-v1.0

# Push Release Branch to Release Repository
# (creates new Branch in Remote Repository)
git push release-repo release-v1.0 master
\end{verbatim}
\end{scriptsize}
\end{beamerboxesrounded}
\end{frame}

% ----------------------------
\subsubsection*{References}

% ----------------------------
\begin{frame}[fragile]{References}
\begin{itemize}
\item Git Webpage (\url{https://git-scm.com/})
\item ProGit (\url{https://git-scm.com/book/en/v2})
\end{itemize}
\end{frame}