git.html 5.8 KB
Newer Older
Florian Moser's avatar
Florian Moser committed
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
<!DOCTYPE html>
<html>
  <head>
    <title>Git & Gitlab</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <link rel="stylesheet" href="css/remark.css">
  </head>
  <body>
    <textarea id="source">

class: center, middle

# Collaboration with git & Gitlab

<img src="images/UZH-logo.png" width="30%">
<br/>
<img src="images/thealternative-logo.jpg" width="30%">

---

# Why _git_

**Change control**
- keep track of who changed what
- revert changes easily
```bash
no more presentation_v2_final_FINAL.pptx
```

**Backup & distribute**
- store important files remotely
- easily copy and maintain on different devices
- share and edit with collaborators
```bash
no more inconsistent state
```

**Focus**
- strict version control helps you to work goal oriented 
```bash
no more chaotic changes
```

---

# Installing _git_
Download *git* for your operating system from [https://git-scm.com/downloads](https://git-scm.com/downloads)

<img src="images/git_download.png" width="100%">

---

Florian Moser's avatar
Florian Moser committed
53 54 55 56 57 58
class: center, middle

# Local workflow with Command Line

---

Florian Moser's avatar
Florian Moser committed
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
# Creating a local repository
open your `Git-Bash`

create a new directory
```bash
mkdir mywebsite
```

change into that directory
```bash
cd mywebsite
```

turn this folder into a git repository
```bash
git init
```

---
# Checking your local repository
you check the status of your repository using
```bash
git status
```

which should give you 
```bash
On branch master

No commits yet

nothing to commit (create/copy files and use "git add" to track)
```
---

# Change something & commit it
In your folder `mywebsite` create a file `helloworld.html` with the content

```html
<html>
	<body>
		<h1>Hello World!</h1>
	</body>
</html>
```

check how git sees that file
```bash
git status
```

which tells you that there are
```bash
No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	helloworld.html

nothing added to commit but untracked files present (use "git add" to track)
```

---

Florian Moser's avatar
Florian Moser committed
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
# Change something & commit it
so let's follow the advice and do 

```bash
git add helloworld.html
```

and then **commit** this change

```bash
git commit -m 'add my first file'
```
you can always check everything you did with
```bash
git log
```

```bash
commit 3b5616d1ba962e7a2e4af1f1bdd54f5d65d4e22d (HEAD -> master)
Author: Oscan Openness <oscar@freedom.org>
Date:   Sun Jan 12 12:20:28 2020 +0100

---

Florian Moser's avatar
Florian Moser committed
147
class: center, middle
Florian Moser's avatar
Florian Moser committed
148

Florian Moser's avatar
Florian Moser committed
149
# Remote workflow with Gitlab
Florian Moser's avatar
Florian Moser committed
150 151 152 153 154 155


---

# Login to gitlab

Florian Moser's avatar
Florian Moser committed
156
create an account (with switch edu) if you have none
Florian Moser's avatar
Florian Moser committed
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

---

# Create a gitlab project (1/2)

<img src="images/gitlab_create_new_project.jpg" width="100%">

---

# Create a gitlab project (2/2)

<img src="images/gitlab_create_new_project_2.jpg" width="100%">

---

# Finish setup gitlab

create a password in the settings  
add an SSH key (optional)

<img src="images/gitlab_project_created.jpg" width="100%">


---

# Finish local setup

<img src="images/gitlab_local_setup_account.jpg" width="100%">
<img src="images/gitlab_local_setup_repository.jpg" width="100%">

(skip the `git init`, `git add .` and `git commit -m "Initial commit` steps)

---

# Add a readme

Florian Moser's avatar
Florian Moser committed
193
explain your project for others and your future self
Florian Moser's avatar
Florian Moser committed
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212

<img src="images/gitlab_add_readme.jpg" width="100%">

---

# Add a license

everything you write has Copyright  
Copyright gives you exclusive rights (no one can use it without permission)  

use a license to define permissions for others  
MIT to allow usage without restrictions  
GPL to allow usage if basic freedom granted to users  
(many others)

<img src="images/gitlab_add_license.jpg" width="100%">

---

Florian Moser's avatar
Florian Moser committed
213 214 215 216 217 218
class: center, middle

# Github Desktop to simplify

---

Florian Moser's avatar
Florian Moser committed
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
# Install github desktop

download from https://desktop.github.com/ 
then open your repository folder

<img src="images/github_add_repository.jpg" width="100%">

---

# Pull changes

download the changes made on gitlab

<img src="images/github_pull_pending.jpg" width="100%">

---

# Commit changes

change your local file  
then preview the changes and then commit

<img src="images/github_changes.jpg" width="100%">

---

# Push changes

push the changes

<img src="images/github_push_pending.jpg" width="100%">

---

# View history

see the changes you've made in the past

<img src="images/github_history.jpg" width="100%">

---

# Introduction done

play around with it!  
we are here to answer questions.

inspiration:
- add some of your documents to git
- change two files but only commit one
- revert changes

ressources:
- https://education.github.com/git-cheat-sheet-education.pdf
- https://git-scm.com/book/en/v2

in 30 Minutes we will start with advanced topics.

---

# Advanced topics

Florian Moser's avatar
Florian Moser committed
281
best-practices for commits  
Florian Moser's avatar
Florian Moser committed
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
create branch & merge request  
create issue & mention it in commit  
use SSH key  
fork & merge back into origin  
add different remotes  

---

# Best practices for commits

- single purpose
```bash
Improve best practice slide
```
- short, imperative subject line
```bash
Add best practice slide
```
- tell why, not how
```bash
Make wording on slides consistent
```

---

# Create branch & merge request

- create branch
```bash
git checkout -b new-branch
```
- push
```bash
git push --set-upstream origin new-branch
```
- merge (on gitlab)

---

# Create issue & mention it in commit  

- create issue on gitlab
- commit local change with `#1` for `1` the issue number
```bash
git commit -m "resolve #1"
```
- push
- go to the issue on gitlab.com and observe

---

# Use SSH key  

- create SSH key
```bash
ssh-keygen -t rsa -b 4096 -C "florian.moser3@uzh.ch" && eval $(ssh-agent -s) && ssh-add ~/.ssh/id_rsa
```
- copy `~/.ssh/id_rsa.pub`
- add the public key on gitlab.com
- clone with SSH
- try out push/pull to see it working

    </textarea>
    <script src="js/remark.min.js" type="text/javascript"></script>
    <script src="js/remark.driver.js" type="text/javascript"></script>
  </body>
</html>