October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

How to Push an Existing Project Folder to GitHub: Choose Git, CLI, or Desktop

Put an existing project folder on GitHub by committing it locally, creating an empty remote repository, and pushing the actual branch name. Choose Git commands, GitHub CLI, or GitHub Desktop.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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

To put an existing project folder on GitHub, create a local Git repository, commit the files you want to keep, create an empty GitHub repository, then connect the two and push your branch. You can do that with Git commands, GitHub CLI, or GitHub Desktop. The steps below are for a folder on your computer that is not already connected to the GitHub repository you intend to use.

Choose the right route before you start

Git is the version-control tool that tracks changes on your computer; GitHub hosts a remote copy of a repository. Initializing a folder locally and creating a repository on GitHub are separate actions. A local commit records a snapshot on your computer; it does not upload the files. Uploading happens when you push a branch.

As an Amazon Associate I earn from qualifying purchases.

  • Use direct Git commands if you want to see and learn each setup step.
  • Use GitHub CLI if you are comfortable in a terminal but want prompts to help create the remote and publish.
  • Use GitHub Desktop if you prefer a graphical interface for publishing an existing project.

If the project already exists on GitHub and you want a working copy on your computer, use git clone instead. Cloning copies a remote project locally; it is different from initializing an existing local folder and pushing it.

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.

Prepare the local folder and files

Open a terminal in the project’s root folder—the directory containing the files you intend to track. Before staging anything, inspect its contents. Do not include passwords, API keys, or other secrets in a repository. Keep sensitive configuration outside the project or exclude it as appropriate.

Check whether the folder already contains a .git directory. If it does, it is already a Git repository: do not blindly initialize it or overwrite its configuration. Review its current branch and remotes first. The commands below assume the folder is not already a Git repository.

Initialize Git and make the first commit

For Git 2.28.0 and later, GitHub documents initializing a new repository with the branch named main like this:

git init -b main

That option is not universal to older Git versions. If your installation is Git 2.27.1 or earlier, use GitHub’s version-appropriate branch-setting procedure rather than assuming -b will work.

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

Stage the files you want included and create the first local snapshot:

git add .
git commit -m "First commit"

git add . stages changes under the current directory, so inspect the folder first and make sure secrets or generated files are not included. Staging selects content for the next snapshot; committing records that snapshot locally. Neither command uploads it.

Create an empty GitHub repository

On GitHub, create a new repository under the personal account or organization where it belongs, provided you have permission to create repositories there. For this existing-local-history workflow, leave the options to add a README, license, or .gitignore unchecked. Starting the remote with its own commit can make it unrelated to the local history and lead to a merge conflict when you try to push.

Authenticate, connect the remote, and push

GitHub requires command-line authentication before you add a local repository using Git. Configure authentication for your environment using GitHub’s current authentication instructions; do not assume a password prompt or SSH setup is already in place.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Copy the repository URL. On the new repository’s Quick Setup page, copy its remote URL.
  2. Add the remote. In the project root, replace REMOTE-URL with the copied URL:
    git remote add origin REMOTE-URL
  3. Verify the remote.
    git remote -v

    You should see the GitHub repository URL for the origin remote.

  4. Push your current branch. If it is named main, run:
    git push -u origin main

    If your branch has another name, substitute that name for main. The -u option sets the upstream relationship for the branch, making later pushes simpler.

GitHub’s instructions for adding locally hosted code cover the command-line setup and push flow.

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

Publish with GitHub CLI or GitHub Desktop instead

These are alternative publication routes; choose one rather than mixing its setup steps with the manual remote procedure above.

GitHub CLI

GitHub CLI can create a repository from an existing local repository, add the remote, and push through guided prompts. Follow GitHub’s local-code instructions for the CLI route.

GitHub Desktop

GitHub Desktop provides a graphical workflow for publishing an existing project. Use GitHub’s procedure for adding an existing project if you prefer point-and-click controls.

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

Fix common first-push problems

  • The push is rejected because the remote already has a commit: Check whether you created the GitHub repository with a README, license, or .gitignore. The straightforward local-history flow uses an empty remote. Do not overwrite or force-push without first understanding what is already on the remote.
  • The command reports that the branch does not exist: Your local branch may not be named main. Check the current branch and use its actual name in git push -u origin BRANCH-NAME.
  • The remote command shows the wrong repository: Review the output of git remote -v and ensure the URL is the intended repository before pushing.
  • A secret was staged but not committed: Remove it from the staged changes before committing, then ensure it is excluded as appropriate. If a secret has already been committed or pushed, removing the file in a later commit does not erase it from repository history; revoke or rotate the exposed credential.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.