This repository was archived by the owner on Oct 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtutorial.tex
More file actions
370 lines (287 loc) · 10.2 KB
/
Copy pathtutorial.tex
File metadata and controls
370 lines (287 loc) · 10.2 KB
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
\documentclass[xcolor=dvipsnames]{beamer}
\usetheme{Rochester}
\usepackage{graphicx}
\usecolortheme[named=OliveGreen]{structure}
\useinnertheme{rounded}
\setbeamertemplate{blocks}[rounded][shadow=false]
\setbeamertemplate{items}[ball]
\begin{document}
\begin{frame}
\frametitle{Netsoc Git Tutorial}
\begin{center}
\includegraphics[scale=0.3]{nat.png}\\
Slides by Tom Mason, Colm Vize and Andrew Anderson
\end{center}
\end{frame}
\begin{frame}
\frametitle{What is a VCS}
Stands for Version Control System.\\
A system used to control collaborative projects, so that multiple people can work on it at the same
time without conflicts (as far as possible).\\
Git is a DVCS, or Distributed CVS. This means that every user has a full copy of the project history.\\
\end{frame}
\begin{frame}
\frametitle{Quick Glossary}
"Working Directory" - The folder with your code in it, that you can edit\\
"commit" - a set of changes to your repository that can be used to bring it from one state to another\\
"push" - sending a bunch of commits somewhere\\
"pull" - grabbing a bunch of commits from somewhere\\
"HEAD" - the latest commit
\end{frame}
\begin{frame}
\frametitle{What is github?}
Github is a hosting site for open source projects using git as their VCS\\
Has a nice WebUI\\
Streamlined Pull requests (more on this later)\\
\end{frame}
\begin{frame}
\frametitle{Create a github repo}
Create a github accont (duh)\\
Create repo (initialise with readme so we can clone it)
\begin{center}
\includegraphics[scale=0.4]{gh-create-repo.png}
\end{center}
\end{frame}
\begin{frame}
\frametitle{Creating local repositories}
You can also create a new repo locally by doing:
\begin{block}{}
mkdir myrepo\\
cd myrepo\\
git init
\end{block}
However, this will have no "remote", so you wan't be able to "push" it anywhere until you add some (more on this later)
\end{frame}
\begin{frame}
\frametitle{Cloning repositories}
Makes a local copy of a repository, from e.g github\\
Works with lot of protocols (http, ssh, native git protocol, even local files).
\begin{block}{Clone a local repository}
git clone /path/to/repo
\end{block}
\begin{block}{Clone a remote repository}
git clone https://github.com/username/your-repo.git
\end{block}
\end{frame}
\begin{frame}
\frametitle{Make your changes}
After the cloning a repo, as on the previous slides, you will have a folder with the repositories
files in it (normally source code for a program).
Make your changes, then
\begin{block}{}
git status
\end{block}
will show what file have changed, and what has been...
\end{frame}
\begin{frame}
\frametitle{Stage files}
staged.
You can stage changes (select them for committing) by using
\begin{block}{}
git add $<$filename$>$ \# adds $<$filename$>$\\
git add . \# also works on directories
\end{block}
\end{frame}
\begin{frame}
\frametitle{Committing changes}
To actually commit these changes use
\begin{block}{}
git commit -m "Commit message"
\end{block}
commits the changes we have added, with the message "Commit Message"\\
\begin{block}{}
git commit
\end{block}
If you don't specify -m "whatever", git will open a text editor, and you can type your commit message in there
Now the file is committed to your local repo, but not on the remote repo \emph{yet}.
\end{frame}
\begin{frame}
\frametitle{Undoing}
Get a list of commits
\begin{block}{}
git log
\end{block}
Beside each commit is a unique SHA hash identifier (the big nasty random looking string)\\
Can use this to go back to any commit
\end{frame}
\begin{frame}
\frametitle{Undoing}
reset to a specific commit
\begin{block}{}
git reset $<$commit-id$>$
\end{block}
This will leave all changes from the commits after it as uncommitted changes in your working directory\\
If you don't want this
\begin{block}{}
git reset --hard $<$commit-id$>$
\end{block}
will reset the working directory to the state of the specified commit.
\end{frame}
\begin{frame}
\frametitle{Undoing}
Can also do
\begin{block}{}
git reset HEAD\^{}1
\end{block}
To revert the last commit, \^{}2 for two commits ago, etc
\end{frame}
\begin{frame}
\frametitle{Remote repositories}
You now have a commit in your local repository that isn't in the remote repository.
You "push" this to the remote using
\begin{block}{}
git push origin master
\end{block}
origin is the name that git gives to the place you cloned a repository from.\\
master is a branch, I will explain that later.
\end{frame}
\begin{frame}
\frametitle{Pulling}
Two copies of the repo (desktop + laptop, say)\\
Make changes, commit and push on desktop\\\vbox{}
What happens to the laptop copy? We use
\begin{block}{}
git pull
\end{block}
Pulls down all commits on the remote repo
\end{frame}
\begin{frame}
\frametitle{Forking on github}
On github, users can "fork" eachother's repos\\
This creates a copy of that user's repo on your account\\
\begin{center}
\includegraphics[scale=0.3]{gh-fork.png}
\end{center}
You then clone the repo from the copy on your account
\end{frame}
\begin{frame}
\frametitle{Making Pull requests}
If you want the original repo owner to pull in some changes from your repo\\
Push to your repo, pull request from the webui
\begin{center}
\includegraphics[scale=0.4]{gh-pullrequest.png}
\end{center}
Enter title, description etc
\end{frame}
\begin{frame}
\frametitle{Merging pull requests}
The sidebar on the original repo owner's page will show a new pull request\\
They can click and use the webui to merge, or they can do it the traditional way with the command line (github has help built in to the page for this)
\begin{center}
\includegraphics[scale=0.4]{gh-mergepullrequest.png}
\end{center}
\end{frame}
\begin{frame}
\frametitle{Branches}
Like a local fork, within your own copy of the repo\\
"master" from before, is just the main, default branch\\
Often used to make branch for a feature\\
Merged into master when feature is done\\
\end{frame}
\begin{frame}
\frametitle{Branches}
To create a local branch called testbranch
\begin{block}{}
git checkout -b testbranch
\end{block}
This will create the branch based on your current branch (master), and switch into it\\
To view branches
\begin{block}{}
git branch
\end{block}
The current branch will have an asterix beside it
To change back to branch master
\begin{block}{}
git checkout master
\end{block}
\end{frame}
\begin{frame}
\frametitle{Branches}
Edit a file on the new branch and commit it\\
Then git checkout master\\
Your changes will have vanished because they are committed to the other branch\\
You can "merge" in changes from a branch into current branch with
\begin{block}{}
git merge testbranch
\end{block}
\end{frame}
\begin{frame}
\frametitle{Conflicts}
What happens if we try to merge or pull and there are conflicts?\\\vbox{}
This is called a merge conflict\\
Git resolves simple merge conflicts automagically\\
Sometimes, we have to do it manually\\
\end{frame}
\begin{frame}
\frametitle{Merge conflicts}
For example, user1 makes repo with file "test" saying "i am a test"\\
user2 clones repo\\
user1 chages to "i are a test", commits, pushes\\
user2 changes to "i am not a test", commits, pulls\\
user2 will then get this error:
\begin{center}
\includegraphics[scale=0.4]{mergeconflict1.png}
\end{center}
\end{frame}
\begin{frame}
\frametitle{Merge conflicts}
git status shows what files you need to fix
\begin{center}
\includegraphics[scale=0.4]{mergeconflict2.png}
\end{center}
\end{frame}
\begin{frame}
\frametitle{Merge conflicts}
Edit the file, and see the section git can't fix
\begin{center}
\includegraphics[scale=0.4]{mergeconflict3.png}
\end{center}
Then fix it manually
\begin{center}
\includegraphics[scale=0.4]{mergeconflict4.png}
\end{center}
Between $<<<<<$ and ===== is user1's version, between ==== and $>>>>>$ is user2's
\end{frame}
\begin{frame}
\frametitle{Merge conflicts}
git add to mark the file as fixed, then git status will show it in green
\begin{center}
\includegraphics[scale=0.4]{mergeconflict5.png}
\end{center}
Then just commit and push as normal\\
Often git will auto merge things, so long as they're not in the same part of the same file
\end{frame}
\begin{frame}
\frametitle{Remotes}
When you clone, a default "remote" is created, origin\\
So "git push origin master" means "push the default branch to the place I got this from"\\
You can add multiple remotes\\
This is useful for other people's forks
\end{frame}
\begin{frame}
\frametitle{Remotes}
Tell git where to get jonnosfork
\begin{block}{}
git remote add jonnosfork https://github.com/jonno/myrepo.git
\end{block}
Download the changes Jonno has made (this won't override your stuff)
\begin{block}{}
git fetch jonnosfork
\end{block}
Then you can "git merge jonnosfork/master"\\
Can also push to remotes if you have permission eg "git push jonnosfork master"
\end{frame}
\begin{frame}
\frametitle{Stashes}
Sometimes want to pull, merge, etc when not finished with a commit\\
"git stash" saves uncommitted changes to a stack of stashes, and remove the from your working dir\\
"git stash pop" will apply the changes like a merge to your working dir and remove from stack\\
\end{frame}
\begin{frame}
\frametitle{Fin}
That is 99\% of what you need to know\\
Great resource: http://git-scm.com/\\
Latex source for slides available here: https://github.com/netsoc/Git-Tutorial\\
Enjoy using git!
\end{frame}
\end{document}