This is an archived version of the course. Please find the latest version of the course on the main webpage.

Chapter 8: git branch

Summary

face Josiah Wang

Quick recap:

  1. You have create branches (git branch new-branch-name)
  2. You have switched between branches (git checkout branch-name)
  3. You have merged branches (git merge branch-name -m "commit message")
  4. You have learnt to rename your branch (git branch -m old-branch-name new-branch-name)

We have only touched the surface of git branching. This only gives you a glimpse of what might be possible when you work with git collaboratively and remotely.

There are more complex things to consider when doing branching.

For example, what if there is a conflict when trying to merge two branches? (You and your teammate updated the same file differently)

Your team will also need an agreed “workflow” when trying to collaborate. Branching is only a tool - you will still need some kind of project management system to decide how to use it.

Unfortunately we will not cover all these in our course (you still have a lot of Python to learn!) The Pro Git book will give you more details on this subject, or you can just search for answers online when you need it.

Branching is really only useful when you are collaborating with someone else remotely on the same repository, for example in a group coursework assignment or project. Even then, for a small group, if you split your tasks well enough and work on different parts of your code at any one time, you might not even need branching.

For our course, you will be doing individual coursework assignments. Thus, you will most likely only need to commit to the main branch most of the time.

This chapter was really more for you to understand what a branch is and how it relates to all the commits you have been doing so far. It may come useful to you in your other courses (or if you are involved in some form of collaborative software development in the future).