-
Notifications
You must be signed in to change notification settings - Fork 1
/
01_version_control.qmd
270 lines (169 loc) · 5.91 KB
/
01_version_control.qmd
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
---
title: "Git, GitHub, Pull Requests, and code reviews"
format:
html: default
revealjs:
output-file: 01_version_control_slides.html
default: true
slide-number: true
transition: fade
footer: Python package development
logo: academy_logo.png
---
## Why use version control?
![](images/tech-comics-version-control.jpeg)
## Why use version control?
![](images/filenames_versions.png)
## Why use version control?
::: {.columns}
::: {.column width="30%"}
![](images/Vadar-VersionControl-300x300.jpg)
:::
::: {.column width="70%" .incremental}
* Keep track of changes
* Backup and restore
* Transparency
* Easier collaboration
* Improved code quality
* Allow experimentation
:::
:::
## Centralized version control
* Single source with the entire history
* Local copy with latest version
. . .
* Examples: SVN, Surround
## Distributed version control
* Local copy has the entire history
* Commit changes to code offline
* Authorative source (origin)
. . .
* Examples: Git, Mercurial
## Git
Git is a powerful tool for managing code changes and collaborating with others on a project.
. . .
Use Git from the *command-line*, or a *graphical user interface*.
. . .
::: {.columns}
::: {.column width="55%" .smaller}
`> git add foo.py`
`> git commit -m "Fixed"`
`> git push`
:::
::: {.column width="45%"}
![](images/GitHubDesktop.png)
:::
:::
## Basic Git commands
:::{.incremental}
* `git add`: adds a file to the staging area
* `git commit`: creates a new commit with the changes in the staging area
* `git status`: shows the current status of your repository
* `git log`: shows the commit history of your repository
* `git stash`: temporarily save changes that are not ready to be committed
:::
## Working with remote repositories
::: {.incremental}
* `git clone`: creates a copy of the codebase on your local machine.
* `git push`: pushes changes back to the remote repository.
* `git pull`: pulls changes from the remote repository.
:::
## {background-color="white"}
![](images/git_staging.png)
## Git hosting platforms
![](images/git_local_remote.png)
## GitHub
::: {.incremental}
* Git repository hosting service
* Collaborate with others on codebase
* **Fork** a repository to work on your own version
* **Pull requests** for code review and merging changes
* **Issue tracking** and project management tools
* **GitHub Pages** for hosting websites
:::
## Demo 1
1. Create a new repository on GitHub
2. Clone the repository to your local machine
3. Add a file
4. Commit the file
5. Push the file to GitHub
## Branching and Merging
* A branch is a separate version of your code that you can work on independently from the main branch.
* `git merge`: merges changes back into the main branch (we will do this from GitHub)
## Pull request workflow {background-color="white" .smaller .incremental}
![](images/git_workflow.png)
::: {.incremental}
1. Create a branch
2. Make changes
3. Create a pull request
4. Review
5. Merge
:::
::: {.notes}
* Clone a repository to work on a copy (optionally: fork first)
* Create a branch for each new feature or fix
* Commit changes and push to remote repository
* Open a pull request to propose changes and request code review
* Merge changes back into the main branch
:::
## Demo 2
1. Create a new branch
2. Make changes
3. Commit the file
4. Create a pull request
5. Get feedback and merge changes
## Best practices
::: {.incremental}
* Commit often
* Use descriptive commit messages
* Keep pull requests small and focused
* Use "issues" to track work
* Review code regularly
* Use .gitignore to exclude files
* Don't commit data (only very small test data)
* Don't commit passwords
:::
## Gettings started
1. Create a [GitHub account](https://github.com)
2. Install [GitHub Desktop](https://desktop.github.com/) (includes Git)
3. Create a new repository on GitHub
## Resources
* [GitHub: quickstart](https://docs.github.com/en/get-started/quickstart/hello-world)
* [RealPython: git and github intro](https://realpython.com/python-git-github-intro/)
## Word list {.smaller .scrollable}
Clone
: making a local copy of a remote repository on your computer.
Remote
: a reference to a Git repository that is hosted on a remote server, typically on a service like GitHub.
Commit
: a record of changes made to a repository, including the changes themselves and a message describing what was changed.
Stage
: selecting changes that you want to include in the next commit.
Push
: sending changes from your local repository to a remote repository.
Pull
: retrieving changes from a remote repository and merging them into your local repository.
Branch
: a separate line of development that can be used to work on new features or bug fixes without affecting the main codebase.
Pull request
: a way to propose changes to a repository by asking the repository owner to "pull" in the changes from a branch or fork.
Stash
: temporarily save changes that are not ready to be committed (bring them back later when needed).
Merge
: the process of combining changes from one branch or fork into another, typically the main codebase.
Rebase
: a way to integrate changes from one branch into another by applying the changes from the first branch to the second branch as if they were made there all along.
Merge conflict
: when Git is unable to automatically merge changes from two different branches, because the changes overlap or conflict.
Checkout
: switching between different branches or commits in a repository.
Fork
: a copy of a repository that you create on your own account, which you can modify without affecting the original repository.
## Summary
::: {.incremental}
* Version control is a tool for managing changes to code
* Git is a version control system (*software*)
* GitHub is a *platform* for hosting and collaborating on Git repositories
* GitHub Desktop is a GUI for Git (and GitHub)
* Pull requests are a way to propose changes to a repository
:::