Git Branch Weeks

Elvenware Logo

TOC

Overview

Learning about branching.

NOTE: This assignment is specific to a particular course or set of courses, but could be edited to be more generic.

Git Branch

Create a new branch and check it out:

git branch week05
git checkout week05

Modify the readme:

geany README.md &

We should add text like this:

  ## Week 05 Branch

  - [Angular Solar Starter Assignment][solar-start]

Now check it in and bush it on the new branch and then push that branch to your BitBucket or GitHub repository:

git status
git add README.md
git commit -m "Week05 Read me"
git push --set-upstream origin week05

NOTE: Your branch in the cloud is the origin in our case. When we talk about the origin, we are referring to our repository on BitBucket or GitHub. The origin doesn't have to be in the cloud or on those sites, but it is in our case.

Take a look at the new branch's metadata:

git branch -a

Now switch back to master and merge in your changes:

git checkout master
git merge week05

It might looks something like this as we merge the week05 README with the master README:

git merge week05
Updating d0aee52..7ae1b47
Fast-forward
README.md | 9 +++++++++
1 file changed, 9 insertions(+)

Week 06 Branch

Now create a week06 branch and modify the readme as we did in week05:

git branch week06
git checkout week06
geany README.md &

The changes might look like this:

  ## Week 06 Branch

  - [Angular Solar Starter Tests Assignment][solar-start-test]

Check the status:

git status
git branch -a

Add in your changes, commit and push your new branch to the cloud (BitBucket/GitHub):

git add .
git commit -m "Week06 Readme"
git push --set-upstream origin week06

Merge Week06 into Master

Now we merge in our changes to the master branch:

git checkout master
git merge week06

NOTE: We don't necessarily have to merge our changes back into master every day. You should merge them, however, before we go on to week 07. The point being that master ends up contains our latest while our branches show our status at the end of each week. This is not the only thing you can do with branches, nor is it even a common strategy, but it fits our goals in this class. In other words, its nice in this class to have a handy record of where we are at the end of each week. But other teams would do very different things with branches. One of our goals, of course, is simply to be sure we understand how to use git branches. The exact way we use them is not important.

Now check the status, and go back to week06 where we will do our work this week:

git branch -a
git checkout week06

A call to git branch -a might look Like this:

$ git branch -a
  a
  master
  week05
* week06
  remotes/origin/HEAD -> origin/master
  remotes/origin/master