Skip to content
Tengzhen edited this page Oct 2, 2021 · 90 revisions

Lab 3

Due Date

Friday Oct 1 by Midnight.

Overview

This week we are going to practice using git to manage multiple simultaneous changes in a single project, and use git merges. To do this we'll continue to add some features to our SSG repos. This lab will help you practice the following:

  • creating multiple branches to work on new features and fix bugs
  • working on multiple code changes in parallel on separate topic branches
  • adding features to existing code
  • using git merge to do fast-forward and three-way-recursive merges
  • fixing merge conflicts
  • how to find and identify commits on GitHub

Step 1. Pick your Features

You are going to make changes to your repo (i.e., you can work on your own code this week). Pick 2 of the following features to add to your project:

  1. Add an optional -l, --lang, and/or \l flag, which indicates the language to use when generating the lang attribute on the root <html> element. For example, --lang fr would mean that the HTML documents are in French, and would include <html lang="fr">, while -l pt-BR would mean the text is using Brazilian Portuguese: <html lang="pt-BR">. By default, use en-CA for Canadian English.
  2. Make sure that the program exits with appropriate error codes in all cases. If there are no errors, exit with 0. Otherwise, exit with a non-zero exit code (e.g., -1).
  3. Add support for inline <code> blocks. In Markdown, enclosing text in a single backtick causes the text to HTML to get rendered as <code>...text...</code>.
  4. Add support for a horizontal rule in Markdown. The Markdown --- should get converted to an <hr> tag.

In your project's GitHub repo, file Issues for each of the features you want to add, and discuss the changes you will make in the Issue's descriptions. Make sure the Issues are complete and detailed.

Step 2. Create Topic Branches

For each of your chosen features, create a new topic branch. For example, if you filed Issue #10 and Issue #11 you need to create 2 new topic branches off of master (or main, depending on what your default branch is):

# change master to main if that's your default branch
$ git checkout master
$ git checkout -b issue-10
$ git checkout -b issue-11

All work for Issue #10 should happen on the issue-10 branch. All work for Issue #11 should happen on the issue-11 branch. None of your work should happen on master! All work should be done on one of the topic branches you just made.

NOTE: you switch between your branches using git checkout issue-10 or git checkout issue-11 (use your branch names). You can only switch branches if your working directory is clean (i.e., you committed any changes).

Step 3. Implement Your Features

Throughout the week work on your two features. You are free to discuss strategies and ideas with your classmates, but you must do your own work in the respective branches you created above (no pull requests this time, sorry!).

Your two features will likely involve modifying the same files and/or functions. This is fine and to be expected. Resist the desire to share any code between branches! Keep all work for each feature in its own topic branch, and touch as little code as possible in each branch. The less code you change, the easier it will be to merge everything later.

You can work on the features one after the other, or in parallel. With software, it's common and often helpful to do more than one thing at a time: if you get stuck on one, you can switch to the other.

One of git's powers is to allow you to have many different versions of the same code all in existence at the same time. This lets you quickly move back and forth between different projects on the same repository, without having to worry about losing your work.

Remember to git add and git commit as you go, and put all your commits on the correct branch. Every change for Issue #10 goes on the issue-10 branch, etc.

Step 4. Merge You First Feature Branch

When you have completed both features, and each branch contains the necessary code, it's time to merge.

We merge into a branch, so start by switching to your default branch (i.e., master or main) and merge the first feature branch (e.g., issue-10):

# change master to main if that's your default branch
$ git checkout master
$ git merge issue-10

This merge should go smoothly, and assuming you haven't changed anything on master since you created your topic branches, git will do a fast-forward merge. Confirm that it did, using git log. If it didn't, determine why not.

Step 5. Merge You Second Feature Branch

After you've merged your first branch, it's time to merge the second (e.g., issue-11):

# change master to main if that's your default branch
$ git checkout master
$ git merge issue-11

This merge will likely require a three-way recursive merge, since git can't fast-forward your master branch. You may also need to deal with merge conflicts.

Make sure you fix any/all merge conflicts before you complete the merge. If you need help, ask on Slack.

When you're done, the master branch should contain the code for both feature branches, and both features should be working. Make sure your merges didn't break anything!

Test, test, test, and test again. Is the master branch still working? Do you need to fix anything before going to the next step? If so, commit to master to correct the problem(s). Keep track of this, and discuss in your blog below.

Step 6. Push your Master Branch to GitHub

Push your fully merged and tested master branch to GitHub:

# change master to main if that's your default branch
$ git push origin master

Step 7. Close your Issues

Close your original issues, and provide a link in the comments to the merge commit on GitHub that closes the feature. On GitHub the URL for a commit follows this format:

https://github.com/username/project-name/commit/commit-sha

For example, the 11a9e21d73df8cbd67db7163b42b30e052fbcca0 commit (which we can shorten to 11a9e21) for this repo is at:

https://github.com/Seneca-CDOT/topics-in-open-source-2021/commit/11a9e21d73df8cbd67db7163b42b30e052fbcca0

When you close your issue, add a comment like this:

Closed by https://github.com/Seneca-CDOT/topics-in-open-source-2021/commit/11a9e21d73df8cbd67db7163b42b30e052fbcca0

Step 8. Write a Blog Post

Write a blog post about the process of working in parallel branches in your project. In your post, include links to everything you discuss (e.g., the project repo, your issues, your merge commits).

Discuss what you did, the changes you made for your features, and the process of doing your merges. What problems did you have? What did you learn? What would you do differently next time?

Submission

When you have completed all the requirements above, please add your details to the table below.

Name Blog Post (URL) Issues URLs Merge Commit URLs
Example Name https://example.com/blog/1 10, 11 ddeaf180, 10b146ff
Tuan Phong Nguyen https://blog.andrewnt.dev/post/osd-600-series-merge-conflict lang flag, hr markdown lang flag, hr markdown
Minsu Kim https://dev.to/mkim219/branching-and-merging-5cm6 #14, #15 bba15fe, 49c160e
Ahmad Rokay https://dev.to/ar/branches-and-merging-lab-3-5hg4 7, 8 f4db2cc, ae1db7d
Japneet Kalra https://dev.to/japneetsingh035/adding-features-to-existing-code-merging-the-branches-31ji Add an optional -l, --lang feature,Add support for a horizontal rule in Markdown,Add support for inline blocks in generated Html pages d7244e14,e59061b
Jia Hua Zou https://medium.com/@jhzou/merging-64cd1f10def7 #15 , #16 #15 , Part of #15 , #16
Roman Rezinkin https://dev.to/romanrezinkin/lab-3-open-source-45bd #19, #21 Issue#19(dcae6b4), Issue#21(662b1c9)
Francesco Menghi https://dev.to/menghif/dealing-with-merge-conflicts-26nj 13, 14 bf1615c, 1b95d5f
Trang Nguyen https://tracy016.medium.com/osd600-working-with-git-merge-and-git-branch-f8cdc9567bfd 5, 6 6df3a,99f6
Thanh Cong Van https://dev.to/tcvan0707/working-with-branch-and-merge-2kfk Issue #9, Issue #10 38691bb,5319fb
Kunwarvir Dhillon https://dev.to/dhillonks/addressing-merge-conflicts-4h99 #13, #15 89ea750, 0e1d4c8
Joshua Li https://dev.to/jli/parallel-updates-21c0 Issue #13 - Inline Code, Issue #14 - <hr> Merge for both, inline code parent, <hr> parent
Tuan Thanh Tan https://dev.to/tuanthanh2067/working-with-parallel-branches-in-git-5jd Issue #18, Issue #19 77d8015,fd58db1
Minh Hang Nguyen https://dev.to/minhhang107/merges-and-conflicts-2de0 #8, #9 bca2d96, 813e9f8
Chi Kien Nguyen https://dev.to/kiennguyenchi/osd600-week-4-lab-3-2iha Lang, Hr Lang, Hr
Andrew Tassone https://dev.to/drew5494/adding-language-support-and-more-the-great-site-generator-1jkl Lang, Error handling Lang, Error Handling
Gus McCallum Blog Issue 1 Issue 2 Merge Commit 1 Merge Commit 2
Antonio Bennett Dev Blog 12, 13 b52938a, 8b70bf0
Minh Quan Nguyen https://dev.to/mqnguyen/branches-and-merges-1me5 10, 11 17156c7, 70f498b
Anatoliy Serputov https://medium.com/@aserputov/lab-3-osd-e9adc8d63b01 7, 8 8591897, 5d999ce
Le Minh Pham https://medium.com/@lmpham1/dps909-new-features-dealing-with-merge-conflicts-e2da89cdc887 lang option, horizontal rule markdown lang commit, <hr/> commit
Vivian Vu https://dev.to/vivianvu/osd600-working-in-multiple-branches-g7d 19, 20 8a6bbe, 159b3d
Jun Song My Blog (੭•̀ᴗ•̀)੭ 12, 13 <code> feature, <hr/> feature
Eugene Chung https://ycechung-opensource.blogspot.com/2021/10/lab-3-merge-conflict-and-resolution.html 28, 29 <error msg> feature, <hr> feature
Roxanne Lee https://medium.com/@Roxanne.Lee/git-merges-607e5fc7aa8a 11, 12 5654ed5, e552ada
Kevan Yang https://dev.to/pandanoxes/lab-3-merging-and-resolving-code-conflict-3304 19, 20 f2608c4, bc7ec05
Andre Willomitzer https://dev.to/andrewillomitzer/my-repo-has-branches-and-their-branches-have-branches-4a18 --lang issue, exitCode issue, error handling --Lang Commit, exitCode/error commit
Tue Nguyen https://dev.to/tuenguyen2911_67/merging-branches-3hi7 Issue 17, Issue 16, Issue 14 f3b10b6, 92040d0
Oliver Pham https://dev.to/oliverpham/first-issue-with-parallel-branches-5hg8 14, 15 39394a1, 164bd60
Reza Poursafa https://medium.com/@rezapscodes/osd600-git-merges-and-simultaneous-changes-bd1660ced28c #16 , #17 7539794 , d0879f8
Hung Nguyen https://dev.to/nguyenhung15913/learning-to-merge-different-branches-4c3o #11 #12 c9f72f1 72efea5
Alex Romanova https://dev.to/sirinoks/merging-isn-t-bad-13d9 lang, exits, hr c1e5c4f, 41a214c, 3317d95
Irene Park https://dev.to/irenejoeunpark/adding-new-feature-of-markdown-in-my-ssg-application-36k4 #14 #15 a601620,c47a249
Gustavo Tavares Blog Post 12, 13 250fad9b, f9776a41
Leyang Yu https://dev.to/lyu4321/adding-features-branches-and-merges-6a8 12, 13, 14 12: d182600, 13: cf3c65d, 37f645a, 14: de86ee8, aef94ca
Xiongye Jiang https://dev.to/derekjxy/merges-on-github-aod #24, #25 c7aecf4, b8882f6
Amasia Nalbandian Diversion 18, 19 d387ecc, 02b322f
James Mai https://dev.to/beamazedvariable/week-4-the-really-helped-out-4p9m 10 11 fdb4d9 for issue-11 and 2a782 for issue-10
Diana Belokon https://dev.to/belokond/working-on-different-branches-in-parallel-2oa4 Issue#10 and Issue#9 81fca65758f777d58b4a191c5e7649b323f3422d, 54261f0a299a126a2324a8251d231da5870ce51b
Mizuho Okimoto https://dev.to/okimotomizuho/open-source-multiple-branches-and-git-merges-2f69 17, 18 45e4957, 9f8b2dc
Luigi Zaccagnini https://dev.to/luigizaccagnini/merging-branches-with-git-199e Issue#10, Issue#9 a36bcf8, acbfa90
Tengzhen Zhao https://dev.to/yodacanada/lab3-fast-forward-merge-and-three-way-recursive-merge-3bog issue#9, issue#10 02598ce, cc8099d
Clone this wiki locally