🚀 Steps to Add a Local Repository to GitHub Using Git
- Authenticate to GitHub on the command line
- Before pushing your local repository, you must authenticate using your GitHub credentials.
- Learn more: About authentication to GitHub
- Create a new repository on GitHub
- Go to GitHub → New Repository.
- Do not initialize the repository with a README, license, or
.gitignorefile — these can be added later after pushing your local project. - Reference: Creating a new repository
- Copy the remote repository URL
- On the repository’s Quick Setup page, click the copy icon next to the URL to copy it to your clipboard.
- (You’ll use this URL in the next command.)
- Open Git Bash
- Launch Git Bash on your computer.
- Navigate to your local project directory
- Use the
cdcommand to switch to the folder containing your local repository.cd path/to/your/project
- Use the
- Add the remote repository URL
- Run the following command to link your local repo to the remote GitHub repo:
git remote add origin REMOTE-URL - Replace
REMOTE-URLwith the actual GitHub repository URL you copied earlier. - More info: Managing remote repositories
- Run the following command to link your local repo to the remote GitHub repo:
- Verify the remote connection
- Confirm that the remote URL is set correctly by running:
git remote -v
- Confirm that the remote URL is set correctly by running:
- Push your local repository to GitHub
- Upload your local files to the GitHub repository using:
git push origin main - If your default branch is named something other than
main(e.g.,masterordev), replacemainwith your branch name. - Learn more: About branches
- Upload your local files to the GitHub repository using: