11<?xml version =' 1.0' encoding =' utf-8' ?>
22<chapter xml : id =" ch-collaboration" >
33 <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 >
374 <section xml : id =" sec-collaborators-prs" >
385 <title >Collaborators and Pull Requests</title >
396 <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.
509 </p >
5110 <definition xml : id =" def-collabotors" >
5211 <statement >
@@ -89,16 +48,19 @@ must name their distinct branches.
8948 </warning >
9049 <note >
9150 <p >
92- One workflow to support multiple collaborators on the same
51+ Our recommendation to support multiple collaborators on the same
9352repository is to <em >never directly commit to the <c >main</c > branch</em >,
9453even if you're the owner.
9554 </p >
9655 <p >
9756To commit to an alternative branch in <c >GitHub.dev</c > or Codespaces, select
9857<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.
10264 </p >
10365 </note >
10466 <p >
@@ -203,21 +165,32 @@ using <c>main</c> as your <q>Branch name pattern</q>, and
203165enabling required pull requests.
204166 </p >
205167 </note >
168+ </section >
169+ <section xml : id =" sec-collaborators-undo-main" >
170+ <title >Undoing accidental commmits to <c >main</c ></title >
206171 <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
208173made to the local copy of <c >main</c > accidentally, but there
209174is a quick-enough fix nonetheless.
210175 </p >
176+ <warning >
177+ <p >
178+ This fix must be done in a Codespace,
179+ not GitHub.dev.
180+ </p >
181+ </warning >
211182 <note >
212183 <p >
213184With branch protection <xref ref =" note-branch-protection" /> enabled,
214185if you accidentally make updates directly to your personal <c >main</c >
215186branch, 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.
217188Try running "Pull" first to integrate your changes.</c >
218189 </p >
219190 <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" />,
221194changing <c >my-new-branch</c > to the branch name you want to create.
222195Use <kbd >Enter</kbd > to execute the command.
223196 </p >
@@ -268,7 +241,7 @@ shared branches.
268241 </definition >
269242 <p >
270243Managing 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
272245that you've given write access to your repository
273246(<xref ref =" sec-collaborators-prs" />). The only difference
274247is that an outside collaborator is creating branches and making commits
@@ -300,7 +273,66 @@ and open a pull request.
300273 <section xml : id =" sec-conflicts" >
301274 <title >Handling Merge Conflicts</title >
302275 <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 >.
304336 </p >
305337 </section >
306338</chapter >
0 commit comments