Command Line Interface (CLI): Uploading Code to GitHub
A clear walkthrough on how to push your project from a local folder to a GitHub repository using core Git commands in the terminal.
Originally written by Carl Mills · January 2018
Overview
This guide explains how to upload a local project - in this case, a simple JavaScript To-Do List app - to GitHub using the Command Line Interface. The same steps apply to any project, whether it's C++, Python, or web-based.
1. Create a New Repository
Start by creating a new repository at github.com/new. Give it a name, optionally add a description, and decide whether to make it public or private.
2. Change to Your Project Directory
Open Terminal and navigate to your project folder using the cd (change directory)
command.
cd /Users/yourname/Documents/ToDoList
The To-Do List project in this example was originally part of a CV website but placed into its own directory for clarity.
3. Initialize a Git Repository
Turn your local folder into a Git repository using git init. This creates a hidden
.git folder that tracks changes.
git init
4. Add Files to the Repository
Use git add . to add all files in the directory to the staging area, preparing them for
the first commit.
git add .
5. Commit Your Changes
Commit the added files with a descriptive message. Each commit represents a version of your code.
git commit -m "first commit"
You can continue to make edits, add them, and commit again - each commit creates a snapshot of your project's progress.
6. Link to Remote Repository
Copy your repository's HTTPS or SSH URL from GitHub, then connect your local repo to the remote one.
git remote add origin https://github.com/username/ToDoList.git
The origin keyword refers to the remote repository address. You can check this link
anytime with
git remote -v.
7. Push to GitHub
Finally, upload your code to GitHub with the git push command.
git push -u origin master
This pushes your local commits to the main branch (master or main), making
your
project visible online.
Next Steps
Once your project is uploaded, you can continue committing new changes and pushing updates. Future posts cover collaborative GitHub commands like branching, merging, and pull requests.
Continue to GitHub CLI Commands →