Skip to main content

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

Section 4.4 Pulling the Upstream main Branch

Exercises

The next step in getting synchronized with the upstream is to pull the changes to the main branch from the upstream repo to your local repo.
Figure 4.4.1 illustrates the state after several commits have been merged into upstream main and those changes have been pulled into the main branch in the local repo.
described in detail following the image
Cloud image illustrating changes being pulled into the local main branch from the upstream main branch.
Figure 4.4.1. Pulling changes from upstream main branch into the local main branch.
This section walks you through the process of pulling changes from the upstream main branch into your local main branch.

1.

To pull the changes from the upstream main branch into your local repo you first need to ensure that main is the active branch in your local repo.
(a)
    Which command can you use to check if main is the active branch?
  • git log
  • The git log command gives information about the commits that have been made to the active branch.
  • git branch main
  • The git branch main command will try to create a new branch with the name main.
  • git status
  • Correct! The git status command can be used to check which branch is active.
  • git switch main
  • The git switch main command will make main main the active branch, not check which branch is active.
Hint.
(b)
    If your active branch is not main which command could you use to make main the active branch?
  • git log
  • The git log command gives information about the commits that have been made to the active branch.
  • git branch main
  • The git branch main command will try to create a new branch with the name main.
  • git status
  • The git status command will give you information about the active branch, it does not switch branches.
  • git switch main
  • Correct! The git switch main command will make main the active branch.
Hint.
Refer back to the section in the previous chapter on switching branches Section 3.3
(c)
Use the commands you have identified in the previous tasks to ensure that main is the active branch. Do not go on until your main branch is the active branch.

2.

The command git pull <remote> <branch> will pull any new commits from the specified branch in the remote repo and add them onto the end of the active branch of your local repo. <branch> can be a name like origin.
Give a git pull command that will pull new commits from the main branch of the upstream repo and add them to your main branch.

3.

    Run the command from Exercise 4.4.2 in the terminal and examine the output.
    It should not contain any error messages. If it does, look at the format of the command from Exercise 4.4.2 and try again.
    Which of the following appear in the output of the git pull command?
  • The file(s) that were changed.
  • The number of additions to the files.
  • The URL of upstream.
  • The number of deletions to the files.
  • All of the branches in your local repository.
Hint.
Make sure you look at all of the lines of output and the color coding of the lines.
You have attempted 1 of 5 activities on this page.