Skip to content

Commit 49467c3

Browse files
MetOffice#23 Separates out conflicts from the forks section
1 parent 931c1b0 commit 49467c3

14 files changed

+272
-149
lines changed

episodes/02-branching.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ When using git you have a wide range of models to pick from.
5252
This means the first rule when collaborating using git is:
5353
“Talk about your branching model.”
5454

55-
A repositories `CONTRIBUTING` file may include details of their branching model.
56-
This information might also be in a repositories `README` file.
55+
A repository's `CONTRIBUTING` file may include details of their branching model.
56+
This information might also be in a repository's `README` file.
5757
If in doubt ask!
5858
You can also look at how other people appear to be contributing to the repository.
5959

episodes/05-forks.md

+145-78
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,11 @@ Your instructor will give you a link to the `git-training-demo`
3333
repository you will be forking.
3434
This is the **upstream** repository for you fork.
3535

36-
::::::::::::::::::::::::::::::::::::: instructor
37-
38-
To create the conflict at the end of the episode
39-
for all learners your co-instructor should
40-
follow along making the same changes the learners
41-
make. The co-instructors PR should be merged
42-
just before the learners open their PRs.
43-
If the co-instructor has the relevant permissions
44-
they can do this themselves while the instructor
45-
is still teaching.
46-
47-
::::::::::::::::::::::::::::::::::::::::::::::::
48-
4936
## Open an Issue
5037

5138
Remember we track our work with Issues.
5239
Open an Issue on the `git-training-demo` repository
53-
for adding yourself to the list of authors in the
54-
`CITATION.cff` file.
40+
to add a file stating your favourite cloud type.
5541

5642
Navigate to the **Issues** tab:
5743

@@ -70,11 +56,20 @@ This is from the template which provides a consistent
7056
structure to the Issues on this repo.
7157
The template has also added the `enhancement` label for you.
7258

73-
Add in a clear title such as "Add Robert FitzRoy to the list
74-
of authors in the CITATION file",
75-
replace 'Robert FitzRoy' with your name.
59+
Add in a clear title such as
60+
"Add mo-fitzroy's favourite cloud type",
61+
replace 'mo-fitzroy' with your GitHub username.
7662
Click **Submit new issue**.
7763

64+
::::::::::::::::::::::::::::::::::::: instructor
65+
66+
It's a good idea to remind learners that
67+
images can be dropped straight into the
68+
Issue description.
69+
An image of a cloud should do!
70+
71+
::::::::::::::::::::::::::::::::::::::::::::::::
72+
7873
## Create a Fork
7974

8075
On the repository Code tab click on the **Fork** dropdown arrow
@@ -129,46 +124,47 @@ Create your feature branch:
129124

130125
```bash
131126
$ cd git-training-demo
132-
$ git switch -c add-citation-fitzroy
127+
$ git switch -c 1_add-favourite-cloud
133128
```
134129

135130
```output
136-
Switched to a new branch 'add-citation-fitzroy'
131+
Switched to a new branch '1_add-favourite-cloud'
137132
```
138133

139-
Add your name to the `CITATION.cff` file,
140-
underneath any existing author names:
134+
::: callout
135+
136+
## Branch Names
137+
138+
Some colleagues prefix the branch name
139+
with the Issue number as shown above.
140+
This helps remind you what the branch is for!
141+
142+
:::
143+
144+
Add in a new file `cloud-mo-fitzroy.md`,
145+
replace `mo-fitzroy` with your username:
141146

142147
```bash
143-
$ nano CITATION.cff
144-
$ cat CITATION.cff
148+
$ nano cloud-mo-fitzroy.md
149+
$ cat cloud-mo-fitzroy.md
145150
```
146151

147152
```output
148-
cff-version: 1.2.0
149-
message: "Met Office Colleagues and Partners"
150-
authors:
151-
- family-names: "Theodorakis"
152-
given-names: "Dimitrios"
153-
orcid: "https://orcid.org/0000-0001-9288-1332"
154-
- family-names: "FitzRoy"
155-
given-names: "Robert"
156-
title: "Met Office Git Training Demo"
157-
version: 2.0.4
158-
doi: 10.4321/zenodo.1234
159-
date-released: 2024-09-23
160-
url: "https://github.com/MetOffice/git-training-demo"
153+
# My Favourite Cloud
154+
155+
Light and fluffy cumulus.
161156
```
162157

163158
Add and commit your changes:
164159

165160
```bash
166-
$ git add CITATION.cff
167-
$ git commit -m "Adds Robert Fitzroy as an author"
161+
$ git add cloud-mo-fitzroy.md
162+
$ git commit -m "Adds Robert Fitzroy's favourite cloud"
168163
```
169164
```output
170-
[add-citation-fitzroy a3c5e13] "Adds Robert Fitzroy as an author"
171-
1 file changed, 2 insertions(+)
165+
[1_add-favourite-cloud a3c5e13] "Adds Robert Fitzroy's favourite cloud"
166+
1 file changed, 3 insertions(+)
167+
create mode 100644 cloud-mo-fitzroy.md
172168
```
173169

174170
Push your changes to your GitHub fork:
@@ -186,8 +182,8 @@ Writing objects: 100% (3/3), 354 bytes | 354.00 KiB/s, done.
186182
Total 3 (delta 2), reused 0 (delta 0), pack-reused 0
187183
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
188184
To github.com:mo-fitzroy/git-training-demo.git
189-
f87bb5c..a3c5e13 add-citation-fitzroy -> add-citation-fitzroy
190-
branch 'add-citation-fitzroy' set up to track 'origin/add-citation-fitzroy'.
185+
f87bb5c..a3c5e13 1_add-favourite-cloud -> 1_add-favourite-cloud
186+
branch '1_add-favourite-cloud' set up to track 'origin/1_add-favourite-cloud'.
191187
```
192188

193189
## Open a Pull Request
@@ -203,9 +199,9 @@ Just like this repository used Issue templates it
203199
also uses a [PR template](https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/creating-a-pull-request-template-for-your-repository).
204200

205201
Check the Issue you opened earlier for the Issue number.
206-
`mo-fitzroy` checks theirs and it was Issue `#7`.
207-
So he changes the line `Fixes <#ISSUE_NUMBER>` to `Fixes #7`.
208-
This will automatically close Issue 7 when the PR is merged.
202+
`mo-fitzroy` checks theirs and it was Issue `#1`.
203+
So he changes the line `Fixes <#ISSUE_NUMBER>` to `Fixes #1`.
204+
This will automatically close Issue 1 when the PR is merged.
209205
We use the keyword `Fixes` here instead of the `Closes`
210206
keyword we used before because this PR comes from a fork[^link-issue-pr].
211207

@@ -219,6 +215,9 @@ which look like this:
219215
- [ ] I have read `CONTRIBUTING.md` and added my name as a Code Contributor.
220216
```
221217

218+
Some open source projects require you to add your name
219+
to a list of contributors.
220+
We will do this later so for now mark the task as complete.
222221
Replace the space in the square checkbox brackets with an `x`
223222
to mark the task as complete:
224223

@@ -230,57 +229,125 @@ Now when you open the PR it should look something like this:
230229

231230
![](fig/github-fork-pr-1.jpeg){alt='A screenshot of a users pull request from their fork back to the upstream git-training-demo repository.'}
232231

233-
This PR number `#8` will close/fix Issue number `#7` (the top left arrow).
232+
This image shows PR number `#8`.
233+
This PR will close/fix Issue number `#7` (the top left arrow).
234234
You can request a review on the top right.
235235
Some repositories will be set up to automatically assign
236236
a reviewer based on how many reviews each team member
237237
currently has open[^auto-assign-pr-review].
238-
The middle arrow shows the checklist items we marked as complete.
238+
The bottom arrow shows the checklist items we marked as complete.
239239

240240
At the bottom of your PR you can see that a review is required
241241
before merging.
242242
All checks have passed, this repository has automatic checks
243243
for trailing whitespace, accidentally adding large files etc.
244244
More information can be found in the optional episode on
245-
pre-commit hooks.
246-
It also tells us **This branch has conflicts that must be resolved** and the conflicting file is `CITATION.cff`.
245+
[pre-commit hooks](./09-pre-commit.md).
246+
247+
The PR will now need to be approved and merged by your instructors.
248+
249+
::::::::::::::::::::::::::::::::::::: instructor
250+
251+
Take a break here!
252+
This will give you and your co-instructor time
253+
to approve, and squash and merge the PRs.
254+
255+
::::::::::::::::::::::::::::::::::::::::::::::::
256+
257+
## Updating a Fork
258+
259+
Our fork is now behind the main upstream repository
260+
by one commit.
261+
We are going to update our fork.
262+
First we need to set the correct upstream remote in git.
263+
264+
Switch back to your forks `main` branch:
265+
266+
```bash
267+
$ git switch main
268+
```
269+
270+
Now run:
271+
272+
```bash
273+
$ git remote -v
274+
```
275+
276+
```output
277+
origin [email protected]:mo-fitzroy/git-training-demo.git (fetch)
278+
origin [email protected]:mo-fitzroy/git-training-demo.git (push)
279+
```
247280

248-
Go to the main `git-training-demo` repositories code tab
249-
and look at the contents of `CITATION.cff`:
281+
This shows the GitHub remote links for our fork.
282+
To set the upstream remote we can run:
283+
284+
```bash
285+
$ git remote add upstream [email protected]:MetOffice/git-training-demo.git
286+
$ git remote -v
287+
```
250288

251289
```output
252-
cff-version: 1.2.0
253-
message: "Met Office Colleagues and Partners"
254-
authors:
255-
- family-names: "Theodorakis"
256-
given-names: "Dimitrios"
257-
orcid: "https://orcid.org/0000-0001-9288-1332"
258-
- family-names: "Hogan"
259-
given-names: "Emma"
260-
title: "Met Office Git Training Demo"
261-
version: 2.0.4
262-
doi: 10.4321/zenodo.1234
263-
date-released: 2024-09-23
264-
url: "https://github.com/MetOffice/git-training-demo"
290+
origin [email protected]:mo-fitzroy/git-training-demo.git (fetch)
291+
origin [email protected]:mo-fitzroy/git-training-demo.git (push)
292+
upstream [email protected]:MetOffice/git-training-demo.git (fetch)
293+
upstream [email protected]:MetOffice/git-training-demo.git (push)
265294
```
266295

267-
Someone else has added their name
268-
before our PR could be merged.
269-
These changes now conflict with the one you made.
270-
In the next episode you will learn how to deal with
271-
conflicts.
296+
Now git knows about the forks upstream repository.
297+
We can fetch the changes to the upstream repository by running:
272298

273-
::::::::::::::::::::::::::::::::::::::::: spoiler
299+
```bash
300+
$ git fetch upstream
301+
```
274302

275-
## Practicing By Yourself
303+
```output
304+
remote: Enumerating objects: 6, done.
305+
remote: Counting objects: 100% (6/6), done.
306+
remote: Compressing objects: 100% (2/2), done.
307+
remote: Total 4 (delta 3), reused 2 (delta 2), pack-reused 0 (from 0)
308+
Unpacking objects: 100% (4/4), 1.10 KiB | 41.00 KiB/s, done.
309+
From github.com:MetOffice/git-training-demo
310+
* [new branch] main -> upstream/main
311+
```
276312

277-
If you're working through this lesson on your own,
278-
you won't see a conflict.
279-
You should still follow the materials through
280-
the next episode on conflicts to learn
281-
what to do when you do encounter a conflict.
313+
We now have access to the `upstream/main` branch.
314+
To merge in the changes on `upstream/main`:
282315

283-
::::::::::::::::::::::::::::::::::::::::::::::::::
316+
```bash
317+
$ git merge upstream/main
318+
```
319+
320+
And push:
321+
322+
```bash
323+
$ git push
324+
```
325+
326+
```output
327+
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
328+
To github.com:mo-fitzroy/git-training-demo.git
329+
f87bb5c..90808ab main -> main
330+
```
331+
332+
Your forks `main` branch is now up to date with the
333+
main `git-training-demo` repositories `main` branch.
334+
335+
::: callout
336+
337+
## Sync via GitHub
338+
339+
This is equivalent of syncing your fork via the GitHub banner
340+
shown earlier:
341+
342+
![](fig/github-fork-sync-fork-button.png){alt='A screenshot of a users repository showing just the banner announcing the repository is a fork and that is up to date with the upstream repository.'}
343+
344+
If your fork is **behind** the upstream repository
345+
GitHub will alert you on the banner.
346+
You can use the **Sync fork** button to update your fork like we did above.
347+
After syncing your fork this way you only need to run `git pull`
348+
on your local `main` branch.
349+
350+
:::
284351

285352
:::::::::::::::::::::::::::::::::::::::: keypoints
286353

0 commit comments

Comments
 (0)