Remote Repository
You might say
My commits only exist on my computer. How can others see them?
Another copy of the same repository, usually in the cloud, used to sync work and collaborateCommits created on your local computer only become visible to teammates or build systems once pushed to a remote repository hosted in the cloud (such as GitHub). origin is the standard nickname for the default remote; commands like clone, push, and pull synchronize history between your local copy and this shared hub.
Know first
Remoteorigin
When to use it
- Check the linked remote addresses$ git remote -vorigin https://github.com/you/my-first-page.git (fetch)
- Name the default remote origin$ git remote add origin https://github.com/you/my-first-page.gitCloning usually sets up origin automatically
- Pull before pushing to avoid rejectiongit pull→git push→Push succeeded ✓
- Clone the same address to get the same history$ git clone https://github.com/you/my-first-page.gitCloning into 'my-first-page'...
When NOT to use it
- Commit secrets or .env files and push them.env holds keys; after pushing anyone can read themNever commit keys or passwords to a repository
- Force push over remote history after a rejectiongit push --force erased the 3 commits a teammate just pushedWhen rejected, pull and merge instead of force pushing
- Push to the wrong remote addressPushed to someone else's repository addressConfirm the address with git remote -v before pushing
- Assume pushing means the site is deployedgit push ✓→The site did not update
Anatomy
https://github.com/you/my-first-page.git
Points to the copy in the cloud; origin is only its name, and renaming does not change the content.
Variants
remote -v
git remote -v
See which remote addresses this repository is linked to
remote add
git remote add origin https://…
When the local repository has no remote address yet
push
git push origin main
Send local commits to the remote repository
pull
git pull origin main
Fetch new remote changes and merge them locally
Typical use cases
git remote -v in a terminal
$ git remote -v
origin https://github.com/you/my-first-page.git (fetch)
origin https://github.com/you/my-first-page.git (push)
Repository page on a hosting site
A rejected push message
$ git push origin main
To github.com:you/my-first-page.git
! [rejected] main -> main (fetch first)
The remote has commits you do not: git pull first, then push
The URL given to git clone
$ git clone https://github.com/you/my-first-page.git
Cloning into 'my-first-page'...
This URL is the remote; cloning links it as origin automatically
Further reading