1
1
<?xml version =' 1.0' encoding =' utf-8' ?>
2
2
<chapter xml : id =" ch-collaboration" >
3
3
<title >Collaborating with Others</title >
4
- <section xml : id =" sec-liveshare" >
5
- <title >Live Share</title >
6
- <p >
7
- A nice feature of collaborative authoring tools such
8
- as Google Docs and Overleaf is the ability for several
9
- collaborators to edit the same file synchronously, with
10
- a feature set similar to <c >GitHub.dev</c >.
11
- </p >
12
- <p >
13
- Using the Extensions sidebar, search for and install
14
- Microsoft's <q >Live Share</q > extension. Once installed,
15
- you will have a <q >Live Share</q > option in your
16
- bottom toolar. Clicking it will automatically copy a URL
17
- ending in
18
- <c >https://.../join?[randomStringOfCharacters]</c >.
19
- If you share this URL with a colleague (or
20
- colleagues) you trust, they will be able to collaboratively
21
- edit your repository's text files with you via their web
22
- browser. When you commit your
23
- changes, they will be listed as co-authors of the commit.
24
- </p >
25
- <remark >
26
- <p >
27
- As of writing, my experience with LiveShare has been hit-or-miss,
28
- so I'll suggest another mechanism for live collaboration.
29
- Sometimes when I'm working on a Git repository
30
- with a collague on Zoom, I'll share my screen and give my collaborator
31
- control of my mouse and keyboard, or vice versa. Obviously
32
- you should only do this with a collaborator you trust, but it's
33
- a simple solution to quickly work together on the same repo!
34
- </p >
35
- </remark >
36
- </section >
37
4
<section xml : id =" sec-collaborators-prs" >
38
5
<title >Collaborators and Pull Requests</title >
39
6
<p >
40
- A particular downside of Live Share (<xref ref =" sec-liveshare" />)
41
- is that it requires
42
- the repository owner to create the Codespace and provision
43
- the Live Share session. As a result, there's no way for a
44
- collaborator to make a contribution via Live Share to a GitHub project
45
- without the active involvement of the repository owner.
46
- </p >
47
- <p >
48
- To address this, one solution is for the repository owner to
49
- add other GitHub users as collaborators.
7
+ A direct way to allow multiple people you trust to work on the
8
+ same repository is to add these GitHub users as collaborators.
50
9
</p >
51
10
<definition xml : id =" def-collabotors" >
52
11
<statement >
@@ -89,16 +48,19 @@ must name their distinct branches.
89
48
</warning >
90
49
<note >
91
50
<p >
92
- One workflow to support multiple collaborators on the same
51
+ Our recommendation to support multiple collaborators on the same
93
52
repository is to <em >never directly commit to the <c >main</c > branch</em >,
94
53
even if you're the owner.
95
54
</p >
96
55
<p >
97
56
To commit to an alternative branch in <c >GitHub.dev</c > or Codespaces, select
98
57
<c >main</c > in the bottom toolbar, then type the name of your new branch,
99
- and select <q >Create new branch</q >. The name of this branch could
100
- be topical, e.g. <c >add-derivative-chapter</c >, but it's also fine to
101
- pick some other unique identifier, e.g. <c >lastname-YYYY-MM-DD</c >.
58
+ and select <q >Create new branch</q >. It's a good idea to name your
59
+ branch in the form <c >UserName/short-description-of-topic</c >,
60
+ or if you're unsure of the topic, you can just use the current
61
+ date: <c >UserName/YYYYMMDD</c >. Note that prefixing with your
62
+ <c >UserName</c > helps prevent two people from accidentally using the same
63
+ branch name.
102
64
</p >
103
65
</note >
104
66
<p >
@@ -203,21 +165,32 @@ using <c>main</c> as your <q>Branch name pattern</q>, and
203
165
enabling required pull requests.
204
166
</p >
205
167
</note >
168
+ </section >
169
+ <section xml : id =" sec-collaborators-undo-main" >
170
+ <title >Undoing accidental commmits to <c >main</c ></title >
206
171
<p >
207
- Finally , there's no button to push that will fix a commit
172
+ Unfortunately , there's no button to push that will fix a commit
208
173
made to the local copy of <c >main</c > accidentally, but there
209
174
is a quick-enough fix nonetheless.
210
175
</p >
176
+ <warning >
177
+ <p >
178
+ This fix must be done in a Codespace,
179
+ not GitHub.dev.
180
+ </p >
181
+ </warning >
211
182
<note >
212
183
<p >
213
184
With branch protection <xref ref =" note-branch-protection" /> enabled,
214
185
if you accidentally make updates directly to your personal <c >main</c >
215
186
branch, attempting to push these from a Codespace will result in
216
- tthe error message <c >Can't push refs to remote.
187
+ the error message <c >Can't push refs to remote.
217
188
Try running "Pull" first to integrate your changes.</c >
218
189
</p >
219
190
<p >
220
- To fix this, open the Terminal and type <xref ref =" lst-branch-fix-1" />,
191
+ To fix this, open a Terminal
192
+ (<xref ref =" remark-terminal-shortcut" />)
193
+ and type <xref ref =" lst-branch-fix-1" />,
221
194
changing <c >my-new-branch</c > to the branch name you want to create.
222
195
Use <kbd >Enter</kbd > to execute the command.
223
196
</p >
@@ -268,7 +241,7 @@ shared branches.
268
241
</definition >
269
242
<p >
270
243
Managing contributions from forked repositories is done using the
271
- same workflow as I recomend for collaborating with trusted colleagues
244
+ same workflow as we recommend for collaborating with trusted colleagues
272
245
that you've given write access to your repository
273
246
(<xref ref =" sec-collaborators-prs" />). The only difference
274
247
is that an outside collaborator is creating branches and making commits
@@ -300,7 +273,66 @@ and open a pull request.
300
273
<section xml : id =" sec-conflicts" >
301
274
<title >Handling Merge Conflicts</title >
302
275
<p >
303
- To come in a future revision of this handbook...
276
+ Perhaps the most complicated scenario when collaborating
277
+ on a Git repository is the dreaded <em >merge conflict</em >.
278
+ </p >
279
+ <definition xml : id =" def-merge-conflict" >
280
+ <statement >
281
+ <p >
282
+ While Git is fairly good about merging together changes
283
+ made by different contributors to different
284
+ files within a project into a cohesive whole, a
285
+ <term >merge conflict</term > can occur when two different
286
+ contributors attempt to make changes to the same file
287
+ (particularly, the same line) at the same time. When the
288
+ second contributor opens a pull request, GitHub will warn
289
+ about this conflict.
290
+ </p >
291
+ </statement >
292
+ </definition >
293
+ <p >
294
+ Handling merge conflicts can be tricky!
295
+ Git/GitHub have various tools to help you review and correct
296
+ a merge conflict. If you're fortunate, you'll be able to resolve
297
+ things on the pull request page: see
298
+ <url href =" https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/addressing-merge-conflicts/resolving-a-merge-conflict-on-github" >
299
+ Resolving a merge conflict on GitHub
300
+ </url > for full details.
301
+ </p >
302
+ <p >
303
+ You'll be presented with files with some strange markers as in
304
+ <xref ref =" listing-merge-conflict" />. The lines between
305
+ <c ><<<<<<< HEAD</c > and
306
+ <c >=======</c > were merged first, and the lines between
307
+ <c >=======</c > and
308
+ <c >>>>>>>> branch-a</c > are the conflicting
309
+ changes trying to be merged.
310
+ </p >
311
+ <listing xml : id =" listing-merge-conflict" >
312
+ <program >
313
+ <input >If you have questions, please
314
+ <<<<<<< HEAD
315
+ open an Issue
316
+ =======
317
+ ask them in Discussions.
318
+ >>>>>>> branch-a
319
+ </input >
320
+ </program >
321
+ <caption >A merge conflict</caption >
322
+ </listing >
323
+ <p >
324
+ You can then choose which change to retain, deleting all the
325
+ extra <c ><<<<<<< HEAD</c >,
326
+ <c >=======</c >, and
327
+ <c >>>>>>>> branch-a</c > lines.
328
+ </p >
329
+ <p >
330
+ However, sometimes the merge conflict is too involved to be
331
+ corrected using the web interface. In that situation, you will
332
+ need to use a Codespace and follow the instructions at either
333
+ <url href =" https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/addressing-merge-conflicts/resolving-a-merge-conflict-using-the-command-line" >Resolving a merge conflict using the command line</url >
334
+ or
335
+ <url href =" https://code.visualstudio.com/docs/sourcecontrol/overview#_merge-conflicts" >Using Git source control in VS Code | Merge conflicts</url >.
304
336
</p >
305
337
</section >
306
338
</chapter >
0 commit comments