How to Push to GitHub
Pushing code to GitHub means to upload your project code to the GitHub.com code-hosting service. In this short article, we’ll show you how to do this using Git.
How to Create a Local Repository
First, you need to have a local repository for your actual project code. (If you already have this, skip to the next section below titled “How to Push to GitHub”.)
Open the command line (“Terminal” on the Mac, “Git Bash” on Windows) and change into your project’s base directory. There, you can create a new Git repository:
$ cd projects/my-project
$ git init
As a first step, you can add all of your current files to the repository and then bundle these in a commit:
$ git add .
$ git commit -m "Initial commit"
How to Push to GitHub
Before you can upload your code to GitHub, you need to create a remote repository in your GitHub account.
Open the GitHub.com interface in your browser. Right on the “Dashboard” view, you can see a button to create a new repository:
Then, on the project’s main page, you can use the green “Code” button to reveal the repository’s remote URL and copy it to your clipboard:
You can then connect this remote repository to your local Git repository with the following command:
$ git remote add origin <remote repository URL>
The final step is to push your changes from your local repository to your new remote repository:
$ git push origin master