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
Local repositorymy-first-page
push ↑pull ↓
origingithub.com/you/my-first-page
git push origin main

A remote repository is another copy of the same repository. You push local commits; others pull to see them; new remote changes come back to you with a pull.

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 rejection
    git pullgit pushPush 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 rejection
    git push --force erased the 3 commits a teammate just pushedWhen rejected, pull and merge instead of force pushing
  • Push to the wrong remote address
    Pushed to someone else's repository addressConfirm the address with git remote -v before pushing
  • Assume pushing means the site is deployed
    git 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
zsh — my-first-page
$ 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
you / my-first-page
github.com/you/my-first-page Public
The web repository and your local one are two copies of the same history
A rejected push message
zsh — my-first-page
$ 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
zsh — my-first-page
$ 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