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 upload a local project to GitHub with Git and SSH, prepare the files and make a local commit, create an empty GitHub repository, add its SSH URL as your remote, then push your branch. First check that the folder contains no passwords, API keys, or other files you do not intend to publish.

Before you start: check the folder and Git status

Open Terminal, Git Bash, or your platform’s terminal in the project’s root folder. If Git already tracks the project, inspect its status and branch before doing anything else:

git status
 git branch --show-current

The branch command prints the current branch name. Use that name when you push; an existing project is not necessarily on main.

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

If the folder is not yet a Git repository, review its contents before staging anything. GitHub warns: “Never git add, commit, or push sensitive information, for example passwords or API keys, to a remote repository.” Add an appropriate ignore file and stage only project files that belong in the repository. GitHub’s local-code instructions use git add . as an example, but that stages everything under the current directory, so inspect what it will include first.

Initialize and commit a new project

For Git 2.28.0 or later, GitHub documents this sequence for a new local repository whose initial branch is main:

git init -b main
git add .
git commit -m "First commit"

If your Git version does not support git init -b, follow GitHub’s documented alternative in the linked instructions. If the project already has a Git repository and its files are committed, do not initialize or create a duplicate first commit.

Set up SSH authentication

SSH lets Git authenticate to GitHub with a key pair rather than asking for a username and personal access token on each visit. GitHub’s SSH overview explains: “With SSH keys, you can connect to GitHub without supplying your username and personal access token at each visit.” The public key is added to your GitHub account; the matching private key stays on your computer. GitHub Docs: About SSH

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

Check for a key before creating one

Look in ~/.ssh for an existing key pair before generating another. Common public-key filenames include id_rsa.pub, id_ecdsa.pub, and id_ed25519.pub. If you find a suitable pair, add its public key to GitHub and make sure the corresponding private key is available to your SSH client. GitHub provides platform-specific steps for checking, generating, and adding keys in its SSH connection guide.

Never share or upload the private key. A passphrase adds protection if someone obtains the key file; an SSH agent can manage a passphrase-protected key for repeated use. GitHub’s SSH passphrase guidance explains agent setup.

Keep key compatibility in mind

GitHub dropped older, insecure SSH key types on March 15, 2022. DSA keys are not accepted for new personal-account keys, and RSA keys generated after November 2, 2021 must use SHA-2 signatures. Older SSH clients may need an update to support SHA-2. See GitHub’s SSH key guidance for current compatibility details.

Create an empty GitHub repository

On GitHub, create a new repository for the project. For this flow—pushing a local repository with its own history—leave the options to add a README, license, or gitignore file unchecked. GitHub recommends starting without those files to avoid a remote history that conflicts with the existing local one. Copy the repository’s SSH URL from its setup page. GitHub documents the full workflow in Adding locally hosted code to GitHub.

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

Add the remote and push your branch

In the project folder, connect the local repository to GitHub. Replace OWNER and REPOSITORY with the values in your copied SSH URL:

git remote add origin git@github.com:OWNER/REPOSITORY.git
git remote -v
git push -u origin main

The remote verification command shows the fetch and push URLs. The final command pushes main and sets it to track the remote branch. If your current branch has another name, substitute that name for main. GitHub documents remote setup and changes in Managing remote repositories.

Fix common first-push problems

Permission denied (publickey)

Check that the public key is registered to the GitHub account with repository access and that the matching private key is available to your SSH client or agent. If an organization requires SAML single sign-on, the SSH key may also need authorization for that organization. See GitHub’s SSH authentication guide and its SAML SSO key authorization instructions.

remote origin already exists

Inspect the configured URLs with git remote -v. If origin points to the wrong repository and should be changed, use git remote set-url origin git@github.com:OWNER/REPOSITORY.git rather than adding a second remote with the same name.

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

The branch cannot be found

Check the branch printed by git branch --show-current and use that name in the push command. Do not assume an older or existing repository uses main.

The push is rejected because the remote has commits

This usually means the GitHub repository was initialized with a file such as a README, so its history differs from the local repository. Do not force-push as a default fix. Inspect both histories and choose a suitable reconciliation method; if you have not yet added project work to the remote, starting again with an empty GitHub repository follows the documented workflow.

You committed a secret

Stop before pushing if the secret is only in a local commit. If it reached GitHub, revoke or rotate the credential promptly: deleting the file in a later commit does not remove the exposed value from earlier history. Follow GitHub’s sensitive-data removal instructions to address repository history.

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

Other ways to publish the project

Git commands are a direct way to learn the Git and SSH steps, but GitHub also documents guided alternatives. GitHub CLI can create a repository from an existing source directory and push it; GitHub Desktop provides a graphical publish flow. Choose based on whether you prefer terminal control or a desktop interface; review files and visibility before publishing with any method.

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

SSH is not the only way to connect Git to GitHub: the remote can also use HTTPS. If you specifically want SSH authentication, use the SSH URL copied from the repository’s setup page.

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.