Web Development with Rails and Git Tutorial

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.

  1. ▶️ 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.

  1. ▶️ In a web browser, create a new repository on GitHub. It needs to be empty, so don’t add anything to it.
  2. ▶️ Follow the instructions given on the GitHub repo page regarding how to share an existing repo (see git remote ... and git push ...).
  3. ▶️ 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).
  4. ▶️ 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.

  1. ▶️ In a web browser, open the GitHub repo page.
  2. ▶️ Click the “Clone or download” button, and copy the HTTPS URL for the repo.
  3. ▶️ In a local terminal, clone the repo using the URL (see git clone ...).
  4. ▶️ Review the state of the working tree to confirm that it was downloaded.
  5. ▶️ 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.

  1. ▶️ Make changes to the working tree.
  2. ▶️ Stage and commit the changes (see git add -A and git commit ...).
  3. ▶️ Review how the state of the repo has changed (see git log --graph --oneline --all --decorate).
  4. ▶️ Push the changes to the remote repo (see git push).
  5. ▶️ Review how the state of the repo has changed (see git log --graph --oneline --all --decorate).
  6. ▶️ 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.

  1. ▶️ Review the state of the repo to confirm that it is out of date (see git log --graph --oneline --all --decorate).
  2. ▶️ 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.
  3. ▶️ 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

  1. ▶️ Alice: Make changes to the working tree.
  2. ▶️ Alice: Stage and commit the changes (see git add -A and git commit ...).
  3. ▶️ Bob: Make changes to the working tree.
  4. ▶️ Bob: Stage and commit the changes (see git add -A and git commit ...).
  5. ▶️ Alice: Push the changes to the remote repo (see git push). This command should complete without error.
  6. ▶️ Bob: Attempt to push the changes to the remote repo (see git push). This command should fail with a merge conflict.
  7. ▶️ Bob: Fetch the changes from the remote repo and merge them into the local repo (see git pull). This command should report merge conflicts.
  8. ▶️ Bob: Update the working tree to remove the merge conflicts.
  9. ▶️ Bob: Stage and commit the changes (see git add -A and git commit ...).
  10. ▶️ Bob: Push the changes to the remote repo (see git push). This command should complete without error.
  11. ▶️ Alice: Fetch the changes from the remote repo and merge them into the local repo (see git pull).
© Scott D. Fleming 2018 • Made with GitHub Pages and Markdown