How to Upload a Project to GitHub

To upload a project to GitHub, create a remote repository, track your local files with Git, make a commit, and push it to GitHub. This guide walks through the process for both a new project and a folder that is already a Git repository, including common first-push errors.

Practice Git workflows →

Before you start

You can use the terminal or GitHub Desktop. The commands below use Git in a terminal and apply to macOS, Windows, and Linux terminals where Git is available.

Step 1: Create an empty GitHub repository

On GitHub, create a new repository and choose its name and visibility. If you are uploading an existing local project, leave options such as adding a README, license, or .gitignore unchecked. That keeps the new remote empty and avoids an unrelated starting commit that can complicate your first push. Copy the repository’s HTTPS or SSH URL; it will look similar to https://github.com/OWNER/REPOSITORY.git.

Step 2: Check the local project

In the project folder, check whether Git already tracks it:

git status
git remote -v

If git status says this is not a Git repository, follow the next section to initialize it. If it shows a branch and working tree status, Git is already initialized; skip initialization and use the existing-repository instructions below. If a remote is already listed, inspect it before adding or changing one.

Step 3: Initialize Git and commit a new project

Only run git init if the folder is not already a Git repository. First create or review .gitignore so generated files, local configuration, and secrets are excluded. Then inspect what Git will stage:

git init
git status --short
git add .
git status
git commit -m "Initial project commit"

Review git status before committing to make sure you are not including credentials, build output, or files you did not intend to publish. The commit records the staged snapshot locally; it does not upload anything by itself.

Step 4: Connect the repository to GitHub and push

If this local repository does not yet have a remote, add the GitHub URL as origin. Check the current branch name, then push that branch:

git branch --show-current
git remote add origin https://github.com/OWNER/REPOSITORY.git
git push -u origin BRANCH-NAME

Replace the URL with the one you copied and replace BRANCH-NAME with the branch printed by git branch --show-current (commonly main). If GitHub authentication is requested, complete the supported browser, credential manager, or SSH flow. Do not put an access token directly in the remote URL.

If origin already exists, do not add it again. Inspect it with git remote -v; if it points to the intended repository, skip the remote-add command. When you need to change a mistaken URL, use git remote set-url origin GITHUB-REPOSITORY-URL after confirming the correct destination.

Step 5: Verify the upload

Open the repository page on GitHub and confirm the expected files and branch appear. You can also check your local branch and remote:

git status
git branch -vv
git remote -v

After the first push, make and commit local changes as usual, then run git push to publish later commits.

Common problems when uploading to GitHub

“remote origin already exists”

A remote named origin is already configured. Run git remote -v to inspect it. Keep it if it is correct; otherwise update it with git remote set-url.

“src refspec main does not match any”

The branch name may differ, or the repository may not have a commit yet. Check git branch --show-current and git status, create a commit if needed, and push the actual branch name. See the refspec error guide.

“failed to push some refs” or a non-fast-forward rejection

The remote may already contain commits, for example because a README was created on GitHub. Fetch and inspect the histories before deciding how to integrate them. Do not force-push as a first fix, since it can overwrite remote work.

Authentication failed

Confirm you have access to the repository and authenticate using GitHub’s current HTTPS or SSH method. A GitHub account password generally cannot be used as a Git HTTPS password; use the supported sign-in flow or configure SSH.

Frequently asked questions

Can I upload a project to GitHub without Git?

GitHub’s website can upload individual files or a small set of files through the browser. For a full project with commit history and repeatable updates, Git is the more practical option.

Should I make the repository public or private?

Choose based on who should be able to view the code and any license or organizational requirements. A public repository is visible to everyone; a private repository limits access to authorized users. Neither setting makes it safe to commit secrets.

Learn Git Faster by Practicing

Reading is just the first step. Real learning happens when you practice.

Start Learning Git →