To push a local project to GitHub, create a repository on GitHub, connect it to your local Git repository as a remote, then push the branch you want to publish. If your project is not yet a Git repository, initialize Git and commit the files first. Before staging anything, check that you have not included passwords, API keys, or other secrets.
Before you push: check the project and its files
These steps assume you are publishing a local project to a new repository on GitHub.com. Open a terminal in the project folder and check whether Git is already tracking it:
git status
If Git reports that the directory is not a repository, initialize it and make an initial commit. Review the files before staging them; exclude credentials, API keys, private certificates, and any other sensitive material. GitHub warns: “Never git add, commit, or push sensitive information, for example passwords or API keys, to a remote repository.” See GitHub’s guidance on adding files to a repository.
If Git is already tracking the project, keep its existing history rather than initializing it again. Check its current branch and remotes before changing anything:
#1 Best Overall
git branch --show-current
git remote -v
Create the GitHub repository
On GitHub.com, create a new repository under the account or organization that should own it. Choose its visibility deliberately: public repositories can be viewed by anyone, while private repositories restrict access to authorized users. For the initial-push workflow below, leave the new repository empty—do not pre-create a README, license, or .gitignore file. Starting with no remote commits avoids an initial-history mismatch.
Copy the repository URL from GitHub’s Quick Setup page. It will typically be an HTTPS or SSH URL. Choose the one that matches your authentication setup and network access; the next section explains the difference.
Connect your local project and push a branch
In the project directory, add the GitHub repository as a remote, confirm the URL, and push the branch you intend to publish:
Rank #2
git remote add origin https://github.com/OWNER/REPOSITORY.git
git remote -v
git push -u origin main
- Replace the example URL with the exact repository URL copied from GitHub.
- Replace
mainwith the name of the branch you want to publish if it is different. Check withgit branch --show-current. - Run
git remote -vto verify thatoriginpoints to the intended repository. - Run the push command. The
-uoption sets the upstream tracking relationship, so later pushes from that branch can usually usegit push.
origin is a conventional name for a remote, not a special GitHub account or setting. A remote is a named URL associated with your local repository. GitHub documents this workflow in Adding locally hosted code to GitHub.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Choose HTTPS or SSH authentication
| Method | What you need | When it may fit |
|---|---|---|
| HTTPS | Supported HTTPS authentication, such as GitHub CLI, a personal access token, or a credential helper such as Git Credential Manager. | Often a practical choice behind firewalls or proxies. HTTPS works for repositories regardless of visibility. |
| SSH | An SSH key pair, with the public key added to your GitHub account. Keep the private key on your machine. | Useful if you already have SSH configured. A firewall or proxy may block SSH connections. |
GitHub no longer accepts your GitHub account password for Git operations over HTTPS. As GitHub Docs puts it, “Password-based authentication for Git has been removed in favor of more secure authentication methods.” If prompted for an HTTPS password, use a personal access token or configure an approved credential helper; GitHub CLI can also handle authentication. Follow GitHub’s current token guidance and grant only the access the task requires. Do not put a token in a command, source file, screenshot, or public message.
For SSH, generate or use an SSH key pair, then add the public key to GitHub. A passphrase may be requested unless your key is available through an agent. If an organization uses SAML single sign-on, its policy may require you to authorize the SSH key or personal access token for that organization. See About authentication to GitHub and Connecting to GitHub with SSH.
Rank #3
If you already have a GitHub repository or remote
Do not run git init or add another remote automatically if the project is already a repository. Inspect the current setup first:
git remote -v
If origin already exists but points to the wrong repository, update its URL rather than adding a duplicate:
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Scan for outdated or missing drivers - takes under a minute3Repair Windows errors before they cause bigger problemsgit remote set-url origin https://github.com/OWNER/REPOSITORY.git
Confirm the result with git remote -v. For remote-management details, see Managing remote repositories.
Use GitHub CLI or GitHub Desktop instead
GitHub CLI
GitHub CLI offers a terminal-based publishing route. From the project directory, its documented repository-creation flow can create a remote repository from the current directory and push the commits. For example, gh repo create --source=. --public creates a public repository; select the visibility that matches your needs rather than copying that flag by default. Consult the current GitHub CLI instructions for adding local code for the available options and authentication setup.
GitHub Desktop
In GitHub Desktop, add the local repository if it is not already listed, then choose Publish repository. Set the repository name, optionally add a description, choose whether it should remain private, select the personal account or organization that should own it, and publish. Screen labels can change over time; check the account, owner, and visibility before confirming. See Adding an existing repository from your local computer to GitHub Desktop.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Troubleshoot common push problems
“remote origin already exists”
List the configured remotes with git remote -v. If origin is already the right URL, use it; if it should point elsewhere, change it with git remote set-url origin <URL>.
Free tools Windows power users keep installed
One-click scans. No signup required.
Best Value
Authentication prompts repeatedly or fails
Check whether the remote URL begins with HTTPS or uses SSH, then use authentication intended for that method. For HTTPS, do not enter your GitHub account password; configure GitHub CLI, a token, or a credential helper. For SSH, confirm that the public key is added to the correct GitHub account. Organization repositories may also require SAML SSO authorization.
The branch name is not main
Check the current branch with git branch --show-current, then replace main in the push command with the branch you intend to publish. GitHub’s example uses main, but your local branch may have a different name.
The push is rejected because the remote has commits
This can happen if the GitHub repository was initialized with a README, license, or other file, or if someone else has added commits. Inspect the local and remote histories and choose an appropriate pull, merge, or rebase workflow before pushing again. There is no safe universal force-push fix: forcing a push can overwrite remote work.
You pushed a secret by mistake
Deleting the file in a later commit does not make an exposed credential safe. Revoke or rotate the credential with its issuer, then follow GitHub’s instructions for removing sensitive data from a repository.
Quick Recap
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.




