Lab 02 - GitHub

Learning goals

In this lab, you are expected to learn/put in practice the following skills:

Updating a single repo

One of the most common tasks that people uses git for is for collaborating. While in general team members organize such that there are no overlapping editing of the files, git is smart enough to avoid clashes when multiple edits are done in the same document1 Team-members could be working on the same file but editing different lines of code. If this is the case, after pull/push, git will integrate the changes without conflicts.. To show this, we will do a collaborative edit of a file!

We will be working with the repository https://github.com/JSC370/whoami

Step 1: Fork the project in your repo

Not a term/command actually available in Git, forking is a feature available in Github (as in other services) that allows users to create copies of other people’s projects to propose changes (i.e. make pull requests, i.e. “I have this great update to your project! Would you like to add it by pulling it into your repo?”).

Importantly, forking preserves the contribution history of everyone who came before you. It’s proper etiquette (and important for academic/intellectual integrity) to not just upload a copy of code as if it were your own!2 In a similar vein: it’s a good idea to put your name/email/copyright in the header or comments of code you publish.

To start you just need to use the Fork button available on the project you would like to contribute to3 For more details, take a look at the Forking Projects article in GitHub guides.:

Source: GitHub Help

Once you “Fork” a project, GitHub will:

  1. Create a copy (using git clone) of that project in your account.

  2. Set up a pipeline to generate pull requests.

Source: GitHub Help

Or

Source: Screenshot!

Once you have a copy of the project in your account, you can proceede by “downloading it” to your computer using the git clone command. For example, if your github user name is statsnerd and the original repository is Spoon-Knife (as in the example), you could use the following in your command line

cd a-place-where-you-want-to-download-the-thing
git clone https://github.com/statsnerd/Spoon-Knife.git

And if you have your ssh credentials set up, you can do instead

cd a-place-where-you-want-to-download-the-thing
git clone git@github.com:statsnerd/Spoon-Knife.git

This way you will get a copy of the repository in your local machine. Now, let’s see how can we update the project!

Step 2: Modifying the corresponding line

If you got the correct copy, you should find a very simple repository with only two files: .gitignore and README.md. The first file is just a reference file for git to know what things it should be “looking at” (checkout the lecture slides), so we will ignore it at this time (pun intended). The second file is the one that we will be playing with. The readme file, which happens to be a Markdown file, contains, or at least will contain, your and your team members biographies. Here is what you need to do:

  1. Find the line with your name.

  2. In that single line (i.e. not spanning multiple lines), write something about yourself, e.g. “I am from XYZ, I love doing ABC, …”.

  3. (optional) if you feel like it, add at the end of the line a picture of yourself (or avatar) using either html or markdown. This will require you to include the figure in the repo (if you are not linking a web fig).

  4. Commit the changes and push the changes to your repo using git commit and git push, e.g.

git commit -a -m "[A short but meaningful message]"
# git add [your-avatar.png] ... if you need to add a picture
git push

You are now one step closer to make your first “pull request”. We will see how that happens in the next part.

Step 3: Do the pull request

This is the final step. Overall, pull requests (PR) are as complex as the proposed changes are. The PR that you are about to make should go smoothly, yet, any time that you make a new PR, the changes should be able to be merged in the original repository without conflicts. Conflicts may only appear if the proposed changes are out-dated with respect to the main repository, meaning that the main repository was modified after your fork and your proposed changes cannot be merged without generating conflicts4 More info about how to deal with conflicts in this very neat post on stackoverflow.com How to resolve merge conflicts in Git. GitHub also has a way to solve conflicts in PRs, but this is only available to the admins of target repo. More info here,. For now, let’s just look at the simple case.

To create the PR, you just need to go to your online copy of the project and click on “Compare & pull request” link:

Source: GitHub Help

This will create a PR in the reference repository. GitHub will automatically analyze the PR and check whether merging the PR to the master branch will result in a conflict or not. If all is OK, then the owner/admin of the repository can merge the PR. Otherwise, if there’s a conflict, you can go back to your local repo, make the needed changes, commit the changes, and push the changes to your copy on github. In this stage, the PR will automatically update to reflect the new changes you made in your copy of the project.

For more information checkout Creating a pull request from a fork on GitHub.

Deliverables

commit aa0ccd6a610e6bca710420b11b1540694a703e6c 
Author: Michael Jongho Moon <michael.jongho.moon@gmail.com>
Date:   Tue Jan 17 12:01:33 2023 -0500

    update for 2023