Getting Up in the GitHub

How do I upload a project on my computer to GitHub?

Seems like an easy question, but if you’ve never done it before, it might be a bit troublesome at first. And while the GitHub Help Documentation is tight, and the Bootcamp articles are super helpful, sometimes people just want a simple walkthrough that explains how to move a project or website they have on their computer to a repository on GitHub.

If you are one of these “people”, then hopefully this short article will help you get all up in GitHub. The process is pretty straightforward, and after you do it once, the next time will be easy. Before we start, we’ll just assume you’ve setup a command line git client and that you’ve already signed up for a GitHub account.

Pushing That Project to GitHub

So let’s say we have a project on our computer, some next level website for example:

$ ls ~/work/next-level/ index.html

The first thing we need to do is initialize a git repository in our project directory:

$ cd ~/work/next-level
$ git init
Initialized empty Git repository in /Users/robert/work/next-level/.git/

Then we need to add our files to be tracked:

$ git add .

And then we can make an initial commit of all our project files:

$ git commit -m "Initial commit."
[master (root-commit) d7b316c] Initial commit.
 2 files changed, 35 insertions(+)
 create mode 100644
 create mode 100644 index.html

So now we have a local git repository for our project, and we’re ready to push our files to GitHub. First, we need to create a repository, and enter a Repository name and optionally a Description on the new repository page. But don’t select the checkbox for Initialize this repository with a README since we want an empty repository because we’re pushing our existing files:

Then back on our computer, we want to create a remote that points to our new GitHub repository. Since we’ll be pushing to this repository, we’ll want to use either the SSH URL or the HTTPS URL. These URLs will always be of the form:

# SSH URL<username>/<repository-name>.git

# HTTPS URL<username>/<repository-name>.git

The new repository page also gives us the URLs we can use to work with our repository, and further down, the page even lists the remaining steps we’ll need to run to push our local repository to GitHub (which we’ll get to in a second):

Now that we know the repository URLs, we can choose one to add a remote that points to our GitHub repository. We’ll use the SSH URL in this example (you’ll need to have setup your SSH Keys to use this URL):

$ git remote add origin

And finally, we can push our project up to GitHub:

$ git push -u origin master
Counting objects: 4, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 865 bytes, done.
Total 4 (delta 0), reused 0 (delta 0)
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.

Refresh that repository page, and we should see our files now:

And that’s it, we’re done, time for profit.

The End.

Hopefully this article was easy to follow, and getting projects from your computer to a repository on GitHub is super clear. Also, if you happen to be new to git and GitHub and want to do more reading, check out the references section below to have knowledge dropped on you.

RTFM and Other Resources