All right.
So next step, I want to talk a little bit more about how push works and specifically the relationship
between a branch that we have locally and then a branch on GitHub.
So to begin with, I'm just going to make a new repository to demonstrate this with a new GitHub repository.
I'm just going to call this push me.
Sure, I'll make it public, I'll create it, and then I'll just copy this line to add the remote.
And now I'm going to make a new repository locally.
I don't have anything going on here.
I'm going to get an IT and then I'll just make a file here.
How about candy?
Sure.
Oh, jeez, I forgot to touch it.
Okay, so I'm going to add that empty file and I'm going to commit create candy file.
All right.
So I'm going to add this remote, right?
We've seen this before.
Get remote, add origins, the URL for that GitHub repository.
Now, when I run this command, if I want to push up my master branch, get push origin master.
What this does, as we've already talked about, is it pushes up my master branch, whatever commits
are on it up to GitHub.
But what is really important to understand is that this will actually create a master branch on GitHub
the very first time.
Right?
There is no branch on GitHub at the moment and there is a branch called Master locally.
So it's going to create a new master branch on GitHub.
And then I have my local master branch and they're connected, as you can see, by this little arrow.
It shows me.
It just says master, pointing to master.
This is something we're going to learn more about in the next section when we talk about fetching and
pulling.
But there's a distinction between the branches you have locally and the branches on GitHub, if I refresh
here.
There we are.
We see the master branch and I see this empty candy file.
Now, usually, well, a lot of the time we want to connect and push our master branch up to the master
branch on GitHub, but we don't have to.
So I want to be very clear about that.
If I do more work here, let's just make another file.
Touch candy and flowers, dot text.
I'll add that and I'll commit m create flowers.
If I do a get push origin master again, this time it doesn't make a new branch called Master on GitHub.
It's already here.
So it's just going to push our master branch to this master branch on GitHub.
It just assumes that's what we want.
That's what we've told it.
If you just specify this, just a single branch name, master, it's going to it get is going to take
our local master branch and push it up to the remote master branch.
So we'll see that.
Hopefully no surprise.
And we see this second file, our second commit show up, but we can actually push to different branches.
So this syntax is not that crazy looking, but right here it's a little bit intimidating when I write
it out with the official definition.
Basically, if we write, get push and then a remote like origin and then I specify a local branch,
a colon and a remote branch.
This would enable me to push a local branch to a remote branch of a different name.
So take the local pancake branch.
That one goes first local on my machine and push it to the origins branch called Waffle.
So I'm going to demonstrate this.
It's nowhere near as common, but I do want to make it clear that there's a distinction.
They don't have to be the same.
You don't have to push master up to master, even though that's the default behavior.
If you just run, get push origin master.
So why don't I make a new branch?
What should this one be called?
How about cats?
So I have this new branch called cats and I'm going to make some changes on it.
Like just add, I guess we'll just make a cats file and no, this is quite the boring repository.
Let's add cats.
I'm on this branch.
Right.
So create Cat's file.
I'm on the cats branch.
If I do a get push origin cats that will push up my local cats branch to a branch on origin that doesn't
exist yet.
It will create it called cats.
But if I instead I don't want that to happen, which I'll just do it first.
So you see that just more practice, right?
The master branch is unchanged.
We don't see cats, but if I go to the cats, branch can toggle them.
Here we see the cats file anyway.
If I instead want to get that work on master.
Not a normal thing to do, but I'm just going to show this.
If I do get push origin and then my local branch cats and then the destination branch on the remote.
This is the syntax local branch that we have on our machine colon and then the name of a branch on GitHub.
So Master or if we had some other branch on GitHub.
Sure, this tells gets to take our local cat's branch and push it up to the origin master branch.
Let's try it.
Okay.
And we see this diagram.
It's not a diagram, really, but we see this.
It says or it tells us it pushed the cat's branch to the master branch this time.
So if I refresh now on the master branch on GitHub, we see that cats file.
Even though we didn't push the master branch from our machine up, we pushed the cat's branch, but
we pushed it to the GitHub master branch.
So I know that's kind of confusing and again, not at all common, but you can do it.
And I just showed it to you to make it clear that there's a distinction between the branch on your machine
and the branch on GitHub.
And when we normally do things like this, get Push Origin Master Yes, we're pushing the master branch
from our machine to the master branch on GitHub.
Normally we want them to be the same, but they don't have to be all right.