Demo 6: Collaboration Using Git and Remote GitHub Repositories
▶️ Play from the beginning (~40 minutes)
In this demonstration, I will explain how to use remote GitHub repositories for collaborative software development. As with the previous demos, I’ll focus on some common development tasks with remotes.
Here is a diagram that expands on the previous anatomy of a local repo to show a high-level structure of remote repos. Note that GitHub repos are “bare” in that they do not have working trees.
Because these are collaborative tasks, I will introduce two developers, Alice and Bob, to perform the tasks.
▶️ 1. Setting Push Mode
Both Alice and Bob perform this step. It saves a setting, so it is only necessary to do this step once.
- ▶️ Set default push mode to
simple
, which is the new default Git prefers (see git config --global push.default simple
). If we don’t set this, we will get a lengthy warning message every time we push.
▶️ 2. Sharing a Local Repo on GitHub
I will perform these steps with the repository I created in the previous two demos.
- ▶️ In a web browser, create a new repository on GitHub. It needs to be empty, so don’t add anything to it.
- ▶️ Follow the instructions given on the GitHub repo page regarding how to share an existing repo (see
git remote ...
and git push ...
).
- ▶️ In a terminal, review the state of the local repo with attention to the remote branches that have been added (
git remote
and git log --graph --oneline --all --decorate
).
- ▶️ From the GitHub repo’s webpage, enter the settings and add collaborators to the project.
▶️ 3. Connecting/Syncing to an Existing GitHub Repo
Both Alice and Bob perform these steps.
- ▶️ In a web browser, open the GitHub repo page.
- ▶️ Click the “Clone or download” button, and copy the HTTPS URL for the repo.
- ▶️ In a local terminal, clone the repo using the URL (see
git clone ...
).
- ▶️ Review the state of the working tree to confirm that it was downloaded.
- ▶️ Review the state of the repo with attention to the remote settings and branches (
git remote
and git log --graph --oneline --all --decorate
).
▶️ 4. Pushing Changes to a Remote Repo - The Fast-Forward Merge Case
Only Alice performs these steps.
- ▶️ Make changes to the working tree.
- ▶️ Stage and commit the changes (see
git add -A
and git commit ...
).
- ▶️ Review how the state of the repo has changed (see
git log --graph --oneline --all --decorate
).
- ▶️ Push the changes to the remote repo (see
git push
).
- ▶️ Review how the state of the repo has changed (see
git log --graph --oneline --all --decorate
).
- ▶️ In a web browser, review the GitHub repo page to see how it has changed.
▶️ 5. Pulling Changes from a Remote Repo - The Fast-Forward Merge Case
Only Bob performs these steps.
- ▶️ Review the state of the repo to confirm that it is out of date (see
git log --graph --oneline --all --decorate
).
- ▶️ Fetch the changes from the remote repo and merge them into the local repo (see
git pull
). This will result in a fast-forward merge.
- ▶️ Review the state of the repo to confirm that it has been updated (see
git log --graph --oneline --all --decorate
).
▶️ 6. Pushing Changes to a Remote Repo - The Merge-Conflict Case
- ▶️ Alice: Make changes to the working tree.
- ▶️ Alice: Stage and commit the changes (see
git add -A
and git commit ...
).
- ▶️ Bob: Make changes to the working tree.
- ▶️ Bob: Stage and commit the changes (see
git add -A
and git commit ...
).
- ▶️ Alice: Push the changes to the remote repo (see
git push
). This command should complete without error.
- ▶️ Bob: Attempt to push the changes to the remote repo (see
git push
). This command should fail with a merge conflict.
- ▶️ Bob: Fetch the changes from the remote repo and merge them into the local repo (see
git pull
). This command should report merge conflicts.
- ▶️ Bob: Update the working tree to remove the merge conflicts.
- ▶️ Bob: Stage and commit the changes (see
git add -A
and git commit ...
).
- ▶️ Bob: Push the changes to the remote repo (see
git push
). This command should complete without error.
- ▶️ Alice: Fetch the changes from the remote repo and merge them into the local repo (see
git pull
).