Getting Started With Version Control — Part II

Working with Git & GitHub like a boss

Roberto Quezada
6 min readMay 2, 2018
Git & GitHub Logos

This is part II of a three-part series on how to get started with version control using Git and GitHub. If you missed the first part, you can go check it out below

In part I of this series we covered the basics of setting up and initializing your very first local git repository. Additionally, we walked through the basic git commands and saving your changes in your project. In part II, we will focus on uploading your project to GitHub and how to keep your local project in sync with your remote repository on GitHub. Let’s do thissss!

Official GitHub Logo

To recap, GitHub is a web-based hosting service for distributed version control using Git itself. In other words, it’s a cloud service/platform where you can save and host versions of your source code/project on the interwebs.

You’ll be able to share and collaborate with other developers using a unique URL GitHub provides you with for your project (a.k.a remote repo). The cool part is that by default, it works with Git so you gain the benefit of having your project immediately under version control.

Sign up for the service if you haven’t already. It’s free to use!

Creating Your First Remote GitHub Repository!

So you’re all signed up right? Fantastic. The first thing we are going to do is create your very first new repository on GitHub!

Once you’re logged in, you should see a + icon right next to your profile avatar at the top nav menu. Click the drop-down arrow and select “New Repository”.

Create New Repository

You will be redirected to a page where you will enter the name of your new project/repo and make a couple more choices.

Creating a new repo

You will be asked if you want your new repo to be public or private. Note, the private option is only made available to you if you signed up for a paid plan. You can check out the pricing on their plans here if you’re interested.

We will assume you are on the free plan so we will keep our project public. If you’ve been following my series, In part I, we created a local git repo and project and put it under version control with git. In this case, we already have an existing project to upload. So, we will keep the “Initialize this repo with a README” option unchecked. Finally, click on that big old green button and let’s create our repo!

Pushing Up Your Local Repository To GitHub

You should now be looking at some instructions on how to get your local version (on your computer) of your project synced up with your “remote” repo on GitHub.

In our case, we will be pushing up our existing local repository to GitHub. This is the second set of instructions highlighted in the red box in the above image.

If you were creating a repo on GitHub first and you had not created a project locally, then the first set of instructions would be the one you’d follow. The first four commands should look familiar to you! 😉

You will be running these git commands on your local terminal on your machine within your local project folder. Your output should look something similar to the below:

Adding remote repo and pushing up local repo to remote

So what exactly are we doing here? What is this git remote add and git push commands you speak of?!

Git remote add

The git remote add command simply tells git which “remote” repo you want your local repo to be in sync with. In our case, the remote repo is the one we created on GitHub.

The command takes a couple of arguments. The first is a short name for your remote repo and the second is the url. If you noticed, when you created the new repo — GitHub provided you with a unique URL that points to your remote repo. In my case, it’s git@github.com:sergeant-q/cool_project.git

It’s common practice to use the term origin as the short name for your remote repo. Instead of referencing your remote repo by the full url, you can now use origin instead. Pretty cool eh?

If you ran the git remote -v command at this point, you’d see that git has set up to fetch and push from your brand spanking new remote repo using the short name of origin. Booya.

git remote command

Git Push

The final step in the process is to officially “push” or upload your local project content upstream to your new remote repo so it has the latest changes and is in sync. You will be using git push quite often in your development workflow.

This command takes two arguments (plus optional options). The first argument is the short name (which you created earlier) and the second is the branch name on your remote repo.

git push <remote> <branch>

If you noticed, we are passing an additional option -u in the command. This is short for — set-upstream. This is essentially telling git to automatically set a default remote branch for the current local branch you’re on. In our case by default it is the master branch. So when you’re ready to push up (or pull down) new changes in the future, you won’t have to explicitly tell git which remote branch you want to do push/pull from while you’re on the master branch. The upstream association would already be set up for you! 😃

Let’s check out what our new and updated remote repo looks like on GitHub! If you’re still on the instructions page, hit refresh on your browser.

Repo on GitHub

Pat yourself on your back my friend. You are now the proud owner of your very first GitHub repo! Look at that beauty! 👍🏼😎 — At this point, your project is online and available for everyone to see!

In the last part of this series, we’ll start adding and making changes to our cool project but we’ll do it like a professional developer and work with git branches! We’ll learn how to create and manage them like a boss 💪🏼

We’ll wrap things up by learning how to merge changes from one branch into our master branch, how to revert any bad changes and discuss what pull requests are all about!

Go check out the finale now!

It’s going to an epic finish! See you guys there.

❤️ Like, Share or Leave A Comment!

If you enjoyed this post, don’t forget to give it a 👏🏼, share it with a friend you think might benefit from it and leave a comment!

Thanks again!

More where this came from

This story is published in Noteworthy, where thousands come every day to learn about the people & ideas shaping the products we love.

Follow our publication to see more product & design stories featured by the Journal team.

--

--

Roberto Quezada

Cool Dad | Former Marine | Transformational Leader | Boston sports junkie. Oh and I do tech stuff!