Skip to main content

GitKit (VSCode Edition): Learn git and GitHub in Context

Section 3.7 Pushing a Branch to Your Origin

You have made the changes necessary to address the issue you were assigned, and you are now ready to upstream those changes. In order to do that, the first step is to get the changes you have made into GitHub so that the upstream maintainers can be told about them.

Exercises

As shown in Figure 3.7.1, this is done by pushing your feature branch to your origin repository. More generally, pushing a branch, copies it from a local repository to a remote repository.
Cloud image of the feature branch to be merged into your origin repository.
Figure 3.7.1. Push Feature Branch to Origin.

1.

    The git branch -l (lower case L, not one) command lists all of the branches that exist in your local repository.
    How many branches are in your local repository?
  • 1 - main
  • Look again, you should see more than just the main branch.
  • 1 - feature branch
  • Look again, you should see more than just the feature branch.
  • 2 - main and feature branch
  • Correct! Your local repository will have both the main branch and your feature branch.
  • 3 or more with differing branch names
  • If you have more than 2 branches perhaps you created a feature branch multiple times by accident.
Hint.
Refer to Figure 3.7.1 and look at the local branches on your machine.

2.

Use your browser to look at your origin repository on GitHub.
(a)
    How many branches appear in your origin repository on GitHub?
  • 1 - main
  • Correct! There is only 1 branch, main in your origin repository on GitHub.
  • 1 - feature branch
  • Look again, your feature branch should not be listed in GitHub as it is only in your local repository.
  • 2 - main and feature branch
  • Look again, your feature branch should not be listed in GitHub as it is only in your local repository.
  • 3 or more with differing branch names
  • Perhaps you aren’t in your origin repository. Make sure you see your GitHub userid in the upper left hand corner of your GitHub tab.
Hint.
Make sure you are in your origin repository, not the upstream repository. Refer to Figure 3.7.1 and look at the origin to see what branches should appear on GitHub.
(b)
Why is there a difference between the branches in your origin repository and your local repository?
Pushing your Feature Branch:

3.

The git push <remote repo name> <branch> command will push the specified branch of your local repo to the specified remote repo (i.e. on GitHub).
Use a command that will push your feature branch from your local repo to your origin repo on GitHub.
Note: You can use the name of the remote repo, so you do not need to use the full URL.

4.

When you attempted to push in Exercise 3.7.3, you should have gotten an authorization error. When this happens VSCode will prompt you in the lower right to open GitPod and configure the authorization. Do that. When done, return to your GitPod workspace and try the push again. It should work.
If you get the same pop up, open it again. Look for the GitHub authorization. Click the "..." menu next to it and edit it. Ensure that "repo" with read/write permissions are set and save it. It will send you to GitHub to complete the authorization. When done, return to your GitPod workspace and try the push again. It should work.
You have attempted of activities on this page.