How to push a new branch to your repo on GitHub via the command line – 042

I’ve never thought about Feb 11 being the meaning of life day…

Let’s assume on your local repo, you’ve created a branch and made some changes to that branch. Now you want to push up to your repo. It doesn’t matter if your repo is a fork of someone else’s repo or if you created the repo from scratch.

Before I push my changes, I like to review the logs. This is totally optional, but a good sanity check from time to time to make sure you’re not sharing your email address.

To review your logs, use the command

> git log

viewing your logs in git that will go up to github

and I see my email address is using the noreply one from GitHub so I can still get credit for my contributions. (See upcoming tip.)

And now I can push these changes up by using the following command:

> git push origin windows-fix

and you can verify these changes in your GitHub repo.

your recently pushed branches: windows-fix

and if you switch to this branch (by clicking the branch name in the previous image), you’ll see the 3 commits listed there.

windows-fix branch showing the 3 commits

If you’re wondering why I’m doing this blog series, it is because I constantly have to look up these commands. That’s the problem you run into when you haven’t been paid to code in 10 years. I’m having to come up with other creative ways to grok this material. I always think this command is either git push <branch-source> <branch-destination> or git push <repo-destination> <repo-source> which neither is the case. The command is actually git push <remote-name> <branch-name> See github documentation. I always forget this because I think that master is the name of the local repo (from doing git push origin master all the time). But again, this isn’t the case. Master is the name of the default branch (and not the repo).

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s