Homework 2

Due: Sunday, February 12 at 11:59 pm

Warning

Pay close attention to the instructions.

Part 1

It is time for us to start on our projects. While the content of your open source project is not the subject of this course, everything else around it is. To start, we will set up a scaffold of our future projects and implement all the pieces that we are able to do at this time. You might have already created a repo in the last homework, and you’re more than welcome to add more features and further develop your project outside of the cadence of the homeworks, but your repo must satisfy the requirements here at a minimum.

Steps

Create

Setup tools

After you’ve created your repo, let’s configure the default tools

We will reenable these later on

Setup README and CONTRIBUTING

Head back to your repo and let’s get a few introductory documents ready.

Your README should look something like this:

Note that GitHub provides a set of helpful “setup” options which you can use to create the CONTIBUTING.md:

Final Checklist

You can use this checklist to ensure you’ve done all the requirements for Part 1:

Part 2

In HW1, you made a pull request with your project proposal. I have now made conflicts in that repository, meaning I have made changes such that git does not know how to merge your changes and my changes. If for some reason you do not see this on your HW1 PR, let me know on slack and I will make one. DO NOT RESOLVE THE CONFLICT FOR YOUR HW1 PR.

We will learn one method of resolving this conflict, and we will do so in a way that many package maintainers like. These steps will be demonstrated in class, all we have to do is follow them.

Update target branch

We want to rebase onto the main branch, so lets make sure thats up to date:

git checkout main
git pull

If you used main as your branch for HW1, you will have a problem here. Thats ok, we can resolve by making a new branch with just our HW1 changes:

git checkout -b hw1
git checkout main
git reset origin/main --hard

Close your HW1 pull request that used the main branch, and reopen a new pull request using this new hw1 branch.

New Branch

Now let’s make a branch off of the branch you used in HW1. We will leave the HW1 branch alone in case we make a mistake, we can always go back to the HW1 branch and create a new branch off of it to try again. If we made changes directly on the same branch as HW1 and made a mistake, we wouldn’t be able to redo this.

From this new branch, in the markdown file for your project, add a link to the repository your just created in Part 1 of this homework and make a new commit.

Rebase

Now we are ready to resolve the conflicts and squash down our commits via a rebase. At this point, our local main branch should be up to date with the remote repository, so we just need to pluck our commits out and reapply them after the latest commit to main.

We can do this by running git rebase -i main. This will present us with a dialog where we can decide what to do with all the commits we are trying to reapply.

With this dialog, we can change the message of our commits, but we can also consolidate or remove commits altogether. For each line, we see an action pick, a sha hash of the git commit, and the commit message. Let’s leave the first commit alone. For each subsequent commit, we can change pick to squash. This will bundle the commit together with the commit above it.

In this example, if we edit the rebase action to look like the above, we will squash all 6 of the commits into a single commit.

When we exit this dialog, we will see what the GitHub UI indicated to us – we have a confict.

git will also provide us some information on how to resolve this:

And if we run git status, we’ll see the file or files that both the main branch and our HW1 branch have tried to update:

If we edit these files, we will see git merge indicators, showing the changes on the main branch vs the changes on our HW1 branch:

To resolve the conflict, edit this file to turn it into the desired result. For example, here is how I would edit my tkp2108.md to apply my changes from HW1:

To complete the rebase, git add the files that were conflicted. Then rather than committing, run git rebase --continue. This will repeat the process on all commits you’re trying to apply, giving you the opportunity to edit your commit message every time. Repeat the process of editing conflicted files, git add them and git rebase --continue until you work through all commits and see the Successfully rebased and updated refs/heads/<your branch> message.

New Pull Request

Now that you’ve successfully rebased your commits, open a new pull request with title HW2. From the GitHub UI, you should see that your pull request does exactly 1 commit matching the collection of changes you wanted to do in your pull request for HW1, and that the GitHub UI provides no indication of any additional merge conflicts. Congratulations, you have successfully rebased and squashed your changes from HW1 in a clean, mergeable pull request.