Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
So far we've created a GitHub account, we've created a remote repository on that account, and we've told our local repository how to find that remote repository. Now we are ready to start putting our commits up on the remote repository for other people to see. If you remember from the introduction, I told you that process is called pushing, and push is the verb that we're going to use. So what we want to do is push our code to the remote branch, and when we do pushes what we are pushing is a branch. So we are on a branch, and we're telling GitHub push this branch up to the corresponding branch on the remote server.
The syntax that we're going to use for that, GitHub actually gave us in their helpful hints here; git push -u origin master, so that's git push, we're going to use the -u option. You are pretty much always going to want to use that, we're going talk about what it is in just a little while. But for now, go ahead and do it; git push -u followed by the alias for the remote repository. Remember, we called it origin. So push to origin, that's the GitHub remote, push to that a branch. And which branch do we want to push? We can take a look real quick and see which branches we have, but I'm going to go ahead and do get push -u origin master.
So I'm going to push up the master branch up there to GitHub. It wants my username for GitHub, and it wants my password. Now you can see that it counts up the objects that we have, it compresses them so that it can send a small data packet to GitHub, and then it writes those objects on the other side. Once it's done with all of those, then it creates this new branch for us. So that new branch gets created, and then it notes at the end, branch master set up to track remote branch master from origin.
That's what the -u option does for us. We will talk about branch tracking a little later. Now let's go back to GitHub real quick. It says when you're done doing these steps then click Continue. So we're going to click Continue here. And now it takes us show page for our project, Explore California, and you can see here's the latest commit that we made and here's a view of the entire project. So we can go through, and we can actually surf those files and see everything that's in there. There's also lots of other things you can do like viewing the commits, viewing a chart of the different commits over time, looking at graphs. Feel free to explore, but at this point now we've pushed our project up on to GitHub.
It now exists there. Let's go back and just look at the command line real quick just to see what it actually did. As with a lot of things, it stored that in the git folder. So git config, you can see now there is a branch definition here and the branch has a remote which is origin, but what is origin? Origin is right up here so that's how master knows where it's going to commit to. It references origin, origin references this URL, and then merge is giving it a reference for what it's going to use, when it's doing merges. We don't need to worry about that at this point.
Now I just want us to also take a look at where it stores these, ls -la .git, in the refs folder, there's a folder called remotes, and inside remotes we now see a file called origin. Actually it's a directory called origin. And inside that directory, you'll see there is our branch master, and if we take a look at that, .git/refs/remotes/origin/master, it's a reference to a shot just like our regular tip of our branch pointed to a shot.
It works exactly like a branch, it just stores them in this different folder called remotes. Now you can see your branches normally would git branch, right? Git branch -r will show you the remote branches, and git branch -a will show you both. It will show you both the local ones and the remote ones. So at this point, we have successfully completed the steps in order to get all of our local code online on the remote repository where other people can see it and start working with it. Before we dive into seeing how we can push and fetch from that repository, I want us to stop and take a look at how we can clone a remote repository.
Because that's the way you will work with an existing repository that someone else has.
Get unlimited access to all courses for just $25/month.Become a member
61 Video lessons · 96118 Viewers
56 Video lessons · 109955 Viewers
71 Video lessons · 78752 Viewers
131 Video lessons · 37776 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.