DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk5 min

First GitHub Project: Prepare, Connect and Push Your Local Code

A practical Git-and-SSH walkthrough for publishing a local project to a new GitHub repository, including safe staging and troubleshooting.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To put a local project on GitHub with Git and SSH, prepare and commit the files locally, create an empty GitHub repository, add its SSH URL as the local origin, then push your branch. Set up SSH authentication before pushing: your private key stays on your computer, and its matching public key must be added to your GitHub account.

Check your local project before you begin

Open Terminal, Git Bash, or your platform’s terminal at the project folder’s root. If the folder is already a Git repository, inspect its state first:

As an Amazon Associate I earn from qualifying purchases.

git status
 git branch --show-current

The branch command prints the current branch name. Use that name in the push command later; do not assume an existing project uses main.

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

If this is a new project that Git is not tracking yet, GitHub’s documented command git init -b main creates a repository with main as its initial branch on Git 2.28.0 or later. For older Git versions, GitHub documents an alternative using git symbolic-ref. See GitHub’s local-code publishing instructions for that older-version path.

Review files and make the first commit

Check the folder contents before staging. GitHub warns: “Never git add, commit, or push sensitive information, for example passwords or API keys, to a remote repository.” Use an ignore file for files that should stay out of version control, and stage only the project files you intend to publish.

git add README.md src/

Replace those example paths with the files and folders that belong in your project. If you have reviewed everything and want to stage all files under the current directory, the documented shortcut is git add .. Then create the initial commit:

git commit -m "First commit"

If the project already has a commit, do not create a duplicate just to follow this example; check git status and continue with the existing history.

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

Set up SSH authentication

SSH lets Git authenticate to GitHub using a key pair. The private key remains on your computer; add the corresponding public key to your GitHub account. GitHub explains: “With SSH keys, you can connect to GitHub without supplying your username and personal access token at each visit.” The public key must be registered before it can authenticate. See GitHub Docs: About SSH.

Check for a key before generating one

Look in ~/.ssh for an existing key pair before making a new one. Common public-key filenames include id_rsa.pub, id_ecdsa.pub, and id_ed25519.pub. If a suitable key already exists, add its public-key file to GitHub and ensure the matching private key is available to your SSH client. GitHub’s steps for checking and generating keys are at Checking for existing SSH keys and Generating a new SSH key and adding it to the ssh-agent.

If you need a key, follow GitHub’s current platform-specific generation steps and add the public key—not the private key—to your account. A passphrase can protect the private key. An SSH agent can manage a passphrase-protected key so you do not have to enter the passphrase repeatedly.

Older key compatibility can cause authentication failures. GitHub stopped accepting older, insecure key types on March 15, 2022; it does not accept DSA keys for new personal-account keys. RSA keys generated after November 2, 2021 must use SHA-2 signatures, which older clients may not support. See GitHub’s protocol security announcement if an older setup is involved.

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.

Create an empty GitHub repository

Create a new repository on GitHub and choose its name and visibility. For this flow—publishing a project whose Git history is already local—leave the repository uninitialized: do not add a README, license, or gitignore during creation. GitHub advises this to avoid conflicts when connecting the existing local repository. Copy the SSH URL shown on the repository page; it has a form like [email protected]:OWNER/REPOSITORY.git, with your account or organization and repository name in place of the examples.

GitHub also supports connecting with HTTPS, but this walkthrough uses SSH because the key setup above is what authenticates the connection. Its local publishing guide is at Adding locally hosted code to GitHub.

Connect the local folder and push it

From the project root, add the SSH address as the remote named origin, inspect the configured URLs, then push the current branch. Replace the URL with the one copied from your repository, and replace main if your branch has a different name.

git remote add origin [email protected]:OWNER/REPOSITORY.git
git remote -v
git push -u origin main

git remote -v displays the fetch and push addresses associated with configured remotes. The -u option sets upstream tracking for the branch, so later pushes can generally use git push. GitHub’s remote-management documentation explains these commands at Managing remote repositories.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Fix common first-push errors

Permission denied (publickey)

Check that the public key is added to the GitHub account you are using and that the matching private key is available to your SSH client or agent. If the repository belongs to an organization that requires SAML single sign-on, the key may also need to be authorized for that organization. See Authorizing an SSH key for use with SAML single sign-on.

remote origin already exists

An origin remote is already configured. Inspect it with git remote -v. If it should point to the new repository, change its URL rather than adding another remote:

git remote set-url origin [email protected]:OWNER/REPOSITORY.git

The push says the branch does not exist

Check the actual local branch name with git branch --show-current, then substitute that name in git push -u origin BRANCH. A branch other than main is valid; the command must match the branch that exists locally.

The push is rejected because the remote has commits

This commonly happens when the GitHub repository was initialized with a README, license, or gitignore even though the local repository already has its own history. Inspect both histories and choose a reconciliation method appropriate to their contents. Do not force-push as a beginner default; it can discard remote history.

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

You committed a secret by mistake

If the secret has not been pushed, stop before pushing and remove it from the commit history. If it was exposed, revoke or rotate the credential promptly; deleting the file in a later commit does not erase its earlier appearance in history. Follow GitHub’s sensitive-data removal guidance for removing committed data safely.

Choose a different publishing interface if needed

Git commands provide direct control over the repository and make the SSH and branch steps visible. If you prefer a guided interface, GitHub CLI can create a repository from an existing source directory and push it, while GitHub Desktop offers a graphical publish flow for an existing repository. These are alternative workflows, not prerequisites for the Git-and-SSH method above. See GitHub Desktop’s existing-project publishing instructions.

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 *

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.

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
Outdated Drivers Are Slowing You DownFree scan - exact matches
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.