Push a New Branch to github that Doesn't Exist Remotely Yet

Chris Achard
InstructorChris Achard
Share this video with your friends

Social Share Links

Send Tweet
Published 4 years ago
Updated 3 years ago

We'll make a new feature branch with:

git checkout -b new-branch

and then when we make changes and commit them, we can try to push that branch with:

git push

However, in order to get the branch to exist on github as well, we need to set the upstream of the local branch at the same time with:

git push --set-upstream origin new-branch

Instructor: [0:00] We can create a new branch in two different ways. We can do git branch and then our branch name like jsChanges or we can do git checkout -b jsChanges. That's what we'll do to make a new branch. If we do a git status, we can see that we're on the branch jsChanges.

[0:20] We can also do git branch to see all of our branches. If we do git branch -vv, for verbose mode, then we can see the current commit that we're on for each branch, and we can see the remote that we're on for each branch. Master is linked to a remote, but jsChanges is just a local branch for now.

[0:42] Let's make a change on this branch. We'll make a function called helloWorld again, and we can say alert i. Then, let's save that and do a git status. Now our app.js has been modified. Let's add app.js to the staging area. We'll commit that and we'll say, "Adds Hello World."

[1:06] If we do a git log oneline, then we have "Adds Hello World" on the jsChanges branch, which has diverged from the master branch. Let's push that. When we do, we get a fatal error, because if we do git branch -vv, we don't have jsChanges linked to any remote branch.

[1:29] Luckily, we have the fix right here. We have to push while setting the upstream to the origin jsChanges, just like this is origin master. Let's do git push. We can do --set-upstream or we can do -u, and then origin jsChanges. Now that has been pushed. If we do git branch -vv again, we can see that jsChanges is now mapped to origin jsChanges.

egghead
egghead
~ 46 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today