Skip to main content

GitKit (2nd ed.): Learn git and GitHub in Context

Section 3.2 Creating a Feature Branch

When you set out to make changes to the project you will do so by working on a feature branch. The exercises in this section will walk you through the process of creating a feature branch on which you will fix the issue that you claimed in Section 2.4.
Figure 3.2.1 illustrates this process. The feature branch that you will create is shown in orange.
Cloud image of origin, upstream, and local branches.
Figure 3.2.1. Create Feature Branch.

Exercises

1.

The git branch <name> command creates a new branch with the given name. When creating a branch, you should give it a short but descriptive name (e.g. FixTypoInReadme). Note: name may not have spaces, so you can use - (dashes) or CammelCaseText to divide words in your branch names. Remember not to include the < > when writing your own command.
(a)
    If you want to create a new feature branch named fixTypoInName, which command should you use?
  • git branch fixTypoInName
  • Correct!
  • git branch <fixTypoInName>
  • The command should not contain < >.
  • branch fixTypoInName
  • The command is missing git.
  • git fixTypoInName
  • The command is missing branch.
Hint.
Look back at the format of the command in the previous description.
(b)
    Adapt the command from Task 3.2.1.a to create a branch for the issue you claimed. Type that command now.
    What output was produced when you typed the git branch command?
  • No output was provided.
  • Correct!
  • It said the branch was created.
  • Look at the terminal window again.
  • It gave an error statement.
  • Your branch was not created. Make sure your branch name does not contain spaces and < >
  • The current branch is <branch name>.
  • Look at the terminal window again.
Hint.
Look back at the format of the command and make sure you type it correctly.

2.

The git branch command without the branch name lists all branches.
(a)
    Type git branch and look at the output produced. Which of the following do you see listed?
  • main
  • Correct!
  • name which is the name of your feature branch
  • Correct!
  • git
  • git is a command and should not be your branch name
  • <name> which is the name of your feature branch
  • The branch name should not have < >.
Hint.
If you don’t see your branch name it means it was not created. Try creating it again using the format of the command from Task 3.2.1.a.
(b)
    By looking at the output provided by git branch how can you tell which is the active branch?
  • It will have an * before the branch name.
  • Correct!
  • The branch name will appear in green.
  • Correct!
  • The branch name will appear in italics.
  • Look at the output provided in the terminal window again.
  • The branch name will appear in bold.
  • Look at the output provided in the terminal window again.
Hint.
There are two ways the active branch is indicated.
Refer back to Figure 3.2.1 to see the process you just completed.
You have attempted 1 of 5 activities on this page.