How to push a new project to GitHub

If you’ve never used Git or GitHub before, you need to understand one of the most important tasks you’ll use with the service: How to push a new project to a remote repository.

For every developer, one of the most important things you can do is interact with GitHub from the command line. By doing this, you can create an empty repository on GitHub and then connect a local repository to that remote. With this setup, you can do everything you need from the local command line.

How do you do this? I’m glad you asked. What I’m going to do is walk you through the process of creating a new remote repository on GitHub and then creating a local repository on your desktop machine and connect the two. This is very basic Git/GitHub stuff, so if you’re already up to speed on how this works move along as there’s nothing for you here.

However, if you’re new to Git/GitHub, keep reading, as this is something you’ll be using quite a lot in your future as a developer.

What you’ll need

The first thing you’ll need is a GitHub account, so head over and sign up. You’ll also need git installed on your platform of choice. I’ll be demonstrating with Ubuntu Server 18.04, but the operating system doesn’t matter, so long as it supports Git.

How to create a new repository on GitHub

The first thing to be done is the creation of a new repository on GitHub. Log in to your GitHub account and go to the Dashboard. From that page click the Repositories tab. In this new window, click New (Figure A).

Figure A

The repository tab in GitHub.

In the resulting window, give the project a name and an optional description (Figure B). Depending on what this project is used for, you might make it private.

Figure B

Creating a new repository on GitHub.

Click Create Repository and GitHub will do it’s thing. The address of the new repository will be:​

To create the commit, issue the command:

git commit -m "added readme"

The next step will make use of the GitHub repository address. What we need to do is add the local repository to the origin (the name of the remote repository where you want to publish your commits) of the remote repository. This is done with the command:

git remote add origin

At this point you can then push your work to the remote with the command:

git push -u origin master

Let’s add another file and push it to the remote repository. Issue the command:


Figure C

We’ve successfully pushed our files to the remote GitHub repository.

Congratulations, you’ve just pushed a new project to GitHub from the command line. Yes, this is very basic stuff, but it’s a task you’ll need to understand as you embark on a career as a developer. Make sure you are well-versed in Git and GitHub, so your path toward developer nirvana is as clear as possible.

Leave a Reply

%d bloggers like this: