Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


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

    Chris AchardChris Achard

    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



    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson




    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.