git remote & git push
Put your project on GitHub
Lesson 13 of 20 · 9 min · Module 4: Working with GitHub
So far your history lives only on this computer. GitHub keeps a copy online, so you can share it, back it up, and work with others.
Start this lesson →Free. No installation: you write and run the code in your browser, and it is checked automatically.
By the end, you’ll be able to…
- Connect a repository to GitHub with a remote
- Push and set the upstream branch
- Know how signing in works on a real computer
The idea
A remote is a nickname for a copy of your repository somewhere else. git remote add origin URL connects your repository to GitHub; origin is the usual name. git push -u origin main uploads your commits and makes main track origin/main, so later a plain git push or git pull knows where to go. On a real computer, the first push asks you to sign in: GitHub accepts a browser sign-in or a personal access token, not your password. The practice terminal is already signed in to its practice GitHub.
git remote add origin https://github.com/learner/website.git
git remote -v
git push -u origin main
01A remote is a nickname for another copy
Your repository can know about copies elsewhere. git remote add origin URL saves the address under the name origin, the usual name for the main copy of a project.
git remote add origin https://github.com/learner/website.git
git remote -vorigin https://github.com/learner/website.git (fetch)
origin https://github.com/learner/website.git (push)02Push and set the upstream
git push -u origin main uploads your commits and remembers that main belongs with origin/main. After that, git status compares your branch with it, and plain git push and git pull know where to go.
git push -u origin mainEnumerating objects: 15, done.
Counting objects: 100% (15/15), done.
Delta compression using up to 8 threads
Compressing objects: 100% (14/14), done.
Writing objects: 100% (15/15), 1.42 KiB | 1.42 MiB/s, done.
Total 15 (delta 4), reused 0 (delta 0), pack-reused 0 (from 0)
remote: Resolving deltas: 100% (4/4), done.
To https://github.com/learner/website.git
* [new branch] main -> main
branch 'main' set up to track 'origin/main'.03Signing in on a real computer
The first time you push, Git asks you to sign in. GitHub accepts a sign-in in the browser or a personal access token, never your account password. Many developers use SSH keys instead, with addresses such as [email protected]:learner/website.git.
Your turn
website. Connect your local repository to it as origin with the address https://github.com/learner/website.git, check the connection with git remote -v, push main with -u, and confirm with git status that you are up to date with origin/main.What the checks look for
- origin points to the GitHub repository
- GitHub has all your commits
- main tracks origin/main
- Confirms that you are up to date
Take this with you
git remote add connects your repository to GitHub; git push -u origin main publishes it.
Go a little further
Run gh repo view to see your repository the way GitHub shows it, and git branch -vv to see which branch tracks which.