Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

To put an existing project folder on GitHub, create a local Git repository, make a commit, create an empty GitHub repository, connect it as a remote, and push your branch. These are separate steps: a local commit saves a snapshot on your computer; pushing uploads that branch to GitHub.

Check the folder before you start

This guide is for files already on your computer that are not yet connected to the GitHub repository you intend to use. Open a terminal in the project’s root folder—the top-level directory that contains the project files.

  • If the folder already contains a .git directory, it may already be a Git repository. Check its status and remote before changing anything; do not initialize it blindly.
  • If the project already exists on GitHub and you want a local copy to work on, use git clone instead. Cloning creates a local copy of a repository that exists remotely. GitHub explains the distinction between local Git work, pushing, and cloning.

Choose a way to publish

Route Interface What it handles Best fit
Git commands Terminal You initialize, commit, add the remote, and push using commands. You want to learn the steps and control each one.
GitHub CLI Terminal with guided prompts Can create the GitHub repository, add the remote, and push from an existing local repository. You prefer a guided terminal workflow.
GitHub Desktop Graphical interface Supports publishing an existing project through point-and-click controls. You prefer not to do the setup manually in the terminal.

Pick one route for the initial publication rather than mixing the graphical publishing flow with the manual remote setup. Official procedures are available for GitHub CLI and GitHub Desktop.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Publish with Git commands

1. Initialize Git and make a first commit

From the project root, initialize the repository and set its initial branch to main:

git init -b main

The -b option is supported by Git 2.28.0 and later. On Git 2.27.1 or earlier, use the branch-setting procedure in GitHub’s guide to adding locally hosted code.

Before staging anything, inspect the project files. Keep passwords, API keys, and other secrets out of the repository. Remove sensitive files from the folder or exclude them with an appropriate .gitignore rule; ignoring a file does not remove it if it has already been staged or committed.

Stage only the files you want in the repository. GitHub’s basic example stages all files in the current folder and creates a first commit:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
git add .
git commit -m "First commit"

Use git status to review what is staged before committing. git add selects files for the next snapshot, and git commit records that snapshot locally; neither uploads anything. GitHub’s overview of Git describes these local operations and the separate push step.

2. Create an empty repository on GitHub

On GitHub, create a new repository under the personal account or organization where you have permission to publish. For this existing-local-history workflow, leave the options to add a README, license, or .gitignore unchecked. An initial commit created on GitHub can be unrelated to your local first commit and may cause a merge conflict when you connect and push the histories. See GitHub’s repository creation instructions.

3. Authenticate and connect the remote

Authenticate Git on your computer with GitHub before attempting command-line operations. The right setup depends on your environment, so follow GitHub’s current authentication and local-code instructions rather than assuming a password prompt or a preconfigured SSH key.

Copy the repository URL from its Quick Setup page, then add it as the remote named origin. Replace REMOTE-URL with the URL you copied:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
git remote add origin REMOTE-URL
git remote -v

The second command verifies the remote URLs Git has saved for the repository.

4. Push your branch

Check the name of your current local branch, then push that branch and set its upstream. If it is named main, run:

git push -u origin main

If your branch has a different name, replace main with the branch name you checked. A successful push sends the committed branch to the GitHub repository; a commit alone does not.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

If something goes wrong

  • GitHub rejects the push because the histories differ: Check whether the remote was initialized with a README, license, or .gitignore. For the basic flow here, use an empty remote; avoid force-pushing unless you understand which history would be overwritten.
  • The push command cannot find the branch: Check the current branch name and use it in the push command instead of assuming it is main.
  • Git prompts for authentication or refuses the connection: Complete the GitHub authentication setup for your environment, then retry.
  • You notice a secret in the staged files: Unstage or remove the file before committing, and make sure it is excluded as appropriate. Do not push credentials; a secret committed to history may remain in that history even if you later delete the file.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.