Connect an existing local repository to GitHub
Connect an existing local repository to GitHub
You already have local commits in notes-app. Now you want GitHub to host a shared copy without losing the history you built locally.
What you’ll learn
- Add and verify a GitHub remote.
- Push an existing branch.
- Explain upstream tracking.
Publish existing history
Local repo
You already have commits.
mainRemote URL
Add GitHub as origin.
git remote addPush
Send main and configure tracking.
origin/main
origin is a conventional remote name, not a special server
After creating an empty repository on GitHub, add its URL as a remote—commonly named origin. The local repository then knows where to fetch from and push to.
git push -u origin main pushes the local main branch and sets its upstream tracking relationship. Later, plain git push and git pull can often use that configured relationship.
Publish your local main branch
Run this in a disposable practice repository unless the lesson explicitly says otherwise.
git remote add origin https://github.com/USERNAME/notes-app.git
git remote -v
git push -u origin mainReplace USERNAME with the actual owner. Authentication may use GitHub CLI, a credential helper/personal access token over HTTPS, or SSH depending on your setup.
Practice: Push an existing project
Your task: After setting an upstream, run git branch -vv and identify the local branch and its tracked remote branch.
Common pitfall to avoid
Copy the remote URL from the intended repository and inspect it with git remote -v. Accidentally pushing to the wrong owner or repository is a preventable configuration mistake.
Check your understanding
Push an existing project: what to remember
Connect an existing local repository to GitHub is complete when you can explain the state being changed before you run the command, not merely repeat the syntax.
Read further: official supporting documentation.
Reaching the recap and completing the quizzes are separate milestones.