@@ -10,7 +10,15 @@ most research groups.
1010
1111## Exercise
1212
13+ In this exercise, we will contribute to a repository via a {term}`pull
14+ request`. This means that you propose some change, and then it is
15+ accepted (or not).
16+
1317::::::{prereq} Exercise preparation
18+
19+ First, we need to get access to some repository to which we will
20+ contribute.
21+
1422:::::{tabs}
1523 ::::{tab} Part of team/exercise room
1624 - Form not too large groups (4-5 persons).
@@ -87,10 +95,10 @@ most research groups.
8795
8896:::{exercise} Exercise: Collaborating within the same repository (25 min)
8997
90- ** Technical requirements** :
98+ ** Technical requirements** (from installation instructions) :
9199- If you create the commits locally: [ Being able to authenticate to GitHub] ( https://coderefinery.github.io/installation/ssh/ )
92100
93- ** What is familiar** from the previous workshop days:
101+ ** What is familiar** from the previous workshop days (not repeated here) :
94102- Cloning a repository ([ previous lesson] ( https://coderefinery.github.io/git-intro/local-workflow/ ) )
95103- Creating a branch ([ previous lesson] ( https://coderefinery.github.io/git-intro/commits/ ) )
96104- Committing a change on the new branch ([ previous lesson] ( https://coderefinery.github.io/git-intro/commits/ ) )
@@ -108,7 +116,10 @@ most research groups.
108116 issue number since you will need it later.
1091171 . Create a new branch.
1101181 . Make a change to the recipe book on the new branch and in the commit
111- cross-reference the issue you opened (see the walk-through below for how to do that).
119+ cross-reference the issue you opened (see the walk-through below
120+ for how to do that).
121+ 1 . Push your new branch (with the new commit) to the repository you
122+ are working on.
1121231 . Open a pull request towards the main branch.
1131241 . Review somebody else's pull request and give constructive feedback. Merge their pull request.
1141251 . Try to create a new branch with some half-finished work and open a draft
@@ -117,10 +128,63 @@ most research groups.
117128:::
118129
119130
120- ## Help and discussion
131+ ## Solution and hints
132+
133+ ### (1) Opening an issue
134+
135+ This is done through the GitHub web interface. For example, you could
136+ give the name of the recipe you want to add (so that others don't add
137+ the same one). It is the "Issues" tab.
138+
139+ ### (2) Create a new branch.
121140
141+ If on GitHub, you can make the branch in the web interface
142+ ({external: doc }` commits ` ). If working locally, you need
143+ {external: doc }` local-workflow ` .
122144
123- ### Pushing local changes to the remote repository
145+
146+ ### (3) Make a change adding the recipe
147+
148+ Add a new file with the recipe in it. Commit the file. In the commit
149+ message, include the note about the issue number, saying that this
150+ will close that issue.
151+
152+ #### Cross-referencing issues and pull requests
153+
154+ Each issue and each pull request gets a number and you can cross-reference them.
155+
156+ When you open an issue, note down the issue number (in this case it is ` #2 ` ):
157+ :::{figure} img/same-repository/issue-number.png
158+ :width: 60%
159+ :class: with-border
160+ :alt: Each issue gets a number
161+ :::
162+
163+ You can reference this issue number in a commit message or in a pull request, like in this
164+ commit message:
165+ ``` text
166+ this is the new recipe; fixes #2
167+ ```
168+
169+ If you forget to do that in your commit message, you can also reference the issue
170+ in the pull request description. And instead of ` fixes ` you can also use ` closes ` or ` resolves `
171+ or ` fix ` or ` close ` or ` resolve ` (case insensitive).
172+
173+ Here are all the keywords that GitHub recognizes:
174+ < https://help.github.com/en/articles/closing-issues-using-keywords >
175+
176+ Then observe what happens in the issue once your commit gets merged: it will
177+ automatically close the issue and create a link between the issue and the
178+ commit. This is very useful for tracking what changes were made in response to
179+ which issue and to know from when until when precisely the issue was open.
180+
181+
182+ ### (4) Push to GitHub as a new branch
183+
184+ Covered in {external: doc }` local-workflow ` .
185+
186+ Push the branch to the repository. You should end up with a branch
187+ visible in the GitHub web view.
124188
125189This is only necessary if you created the changes locally. If you created the
126190changes directly on GitHub, you can skip this step.
@@ -189,47 +253,15 @@ $ git remote set-url origin NEWADDRESS
189253:::::
190254
191255
192- ### What is a protected branch? And how to modify it?
193-
194- A protected branch on GitHub or GitLab is a branch that cannot (accidentally)
195- deleted or force-pushed to. It is also possible to require that a branch cannot
196- be directly pushed to or modified, but that changes must be submitted via a
197- pull request.
198-
199- To protect a branch in your own repository, go to "Settings" -> "Branches".
200-
256+ ### (5) Open a pull request towards the main branch
201257
202- ### Cross-referencing issues and pull requests
258+ This is done through the GitHub web interface. We saw this in, for
259+ example, {ref}` begin-pull-request `
203260
204- Each issue and each pull request gets a number and you can cross-reference them.
205261
206- When you open an issue, note down the issue number (in this case it is ` #2 ` ):
207- :::{figure} img/same-repository/issue-number.png
208- :width: 60%
209- :class: with-border
210- :alt: Each issue gets a number
211- :::
262+ ### (6) Reviewing pull requests
212263
213- You can reference this issue number in a commit message or in a pull request, like in this
214- commit message:
215- ``` text
216- this is the new recipe; fixes #2
217- ```
218-
219- If you forget to do that in your commit message, you can also reference the issue
220- in the pull request description. And instead of ` fixes ` you can also use ` closes ` or ` resolves `
221- or ` fix ` or ` close ` or ` resolve ` (case insensitive).
222-
223- Here are all the keywords that GitHub recognizes:
224- < https://help.github.com/en/articles/closing-issues-using-keywords >
225-
226- Then observe what happens in the issue once your commit gets merged: it will
227- automatically close the issue and create a link between the issue and the
228- commit. This is very useful for tracking what changes were made in response to
229- which issue and to know from when until when precisely the issue was open.
230-
231-
232- ### Reviewing pull requests
264+ You review through the GitHub web interface.
233265
234266Checklist for reviewing a pull request:
235267- Be kind, on the other side is a human who has put effort into this.
@@ -244,8 +276,12 @@ Checklist for reviewing a pull request:
244276- Again, be kind and constructive.
245277- Later we will learn how to suggest changes directly in the pull request.
246278
279+ If someone is new, it's often nice to say something encouraging in the
280+ comments before merging (even if it's just "thanks"). If all is good
281+ and there's not much else to say, you could merge directly.
282+
247283
248- ### Draft pull requests
284+ ### (7) Draft pull requests
249285
250286Try to create a draft pull request:
251287:::{figure} img/same-repository/draft-pr.png
@@ -267,3 +303,22 @@ Draft pull requests can be useful for:
267303 signaling that it is ready to merge.
268304- ** Information** : They can help communicating to others that a change is coming up and in
269305 progress.
306+
307+
308+ ### What is a protected branch? And how to modify it?
309+
310+ A protected branch on GitHub or GitLab is a branch that cannot (accidentally)
311+ deleted or force-pushed to. It is also possible to require that a branch cannot
312+ be directly pushed to or modified, but that changes must be submitted via a
313+ pull request.
314+
315+ To protect a branch in your own repository, go to "Settings" -> "Branches".
316+
317+
318+
319+ ### Summary
320+
321+ - We used all the same pieces that we've learned the last two days
322+ - But we successfully contributed to someone else's project!
323+ - The pull request allowed us to contribute without changing directly:
324+ this is very good when it's not mainly our project.
0 commit comments