Skip to content

Learn Github Exercises

Christian Battista edited this page Apr 28, 2017 · 2 revisions

Onboarding Exercise

Here are some exercises to get you used to github. If you get hung up ask @cbattista for assistance. Use the command line (not github desktop) to interact with git and manage your code.

Basics - Clone and Commit

  1. Clone the onboarding repository onto your local machine. Make sure you use the ssh link, not the https link, or you will have annoying problems later.
  2. Address the Issue with your name on it (e.g., Christian's Bio). Create a markdown file containing a little bit of information about yourself, in a file called yourname_bio.md. Just a few lines is all that is necessary, we will have you add to it later on in the exercises.
  3. Commit and push your file up to the repository, using the commit message to automatically close the issue.

Intermediate - Branching and Merging

  1. Open a new Issue called 'Yourname's Expanded Bio'. Make sure it is attached to the 'Bios' milestone.
  2. Create a new branch named after your first name, and switch to this branch.
  3. Add some new information about yourself in your bio file.
  4. Commit and push this file up the repository, again using the commit message to indicate which Issue it's addressing.
  5. Submit a Pull Request so that your branch can be merged with the master branch.
  6. Wait a few minutes for your lab mentor to approve this Pull Request. If they don't, try to get their attention by adding a comment to the Pull Request, using @theirname to make sure they are notified.

Advanced - Merge Conflicts

Merge conflicts can occur when Pull Requests can't be automatically merged like in the section above. This can happen because changes have been made to the same files in the master branch and in another branch. In this case, we have to manage the Merge ourselves.

Let's learn to manage a Merge by creating a conflict, and then fixing that conflict.

We'll start by making a branch.

  1. Create an Issue called 'Yourname's Favorite Food'.
  2. Create a new branch called 'yourname_food', and switch to this branch.
  3. Add your favorite food to your bio, commit this change and push.

Now, to create the conflicting version.

  1. Switch back to the master branch.
  2. Add your favorite food to your bio, but this time, write the wrong food. Then commit this change and push.

Now, let's try to merge these two branches.

  1. Visit the onboarding repository on github. Submit a Pull Request to merge the yourname_food branch and the master branch. You will get an error message telling you the branches can't be automatically merged. This is OK. This is the exact situation we are learning to deal with.
  2. Switch to yourname_food branch, and run 'git merge master'.
  3. Open your bio file and you'll see something that looks like this, which is some text telling you what the two versions of your bio file look like according to the HEAD branch (which is yourname_food) and according to the master branch.
```
<<<<<<< HEAD
Favorite Food: Pizza
=======
Favorite Food: Poison
>>>>>>> master
```
  1. Keep the parts you want from this block of text, and remove the rest.
  2. Commit your change.
  3. Switch to master branch.
  4. Complete the merge using 'git merge --no-ff yourname_food'
  5. Push to the repo, and see that the Pull Request has been carried out on github, and that the 'Favorite Food' Issue you made is now closed as a result of your code being merged into master.