← Git

Remote Work

What is a remote in Git, and what is `origin`?

Show answer — try answering out loud first

A remote is a version of the repository hosted somewhere else (usually a server like GitHub) that you sync your local repo with. origin is the default name Git gives to the main remote, generally the one you cloned from. It's just an alias for a URL.

When you work on a team, there's a copy of the repo in the cloud that everyone shares. That copy is a remote. You have your local copy and you sync with the remote by doing push (upload) and pull (download).

origin isn't magic at all: it's simply the name (alias) Git gives to the main remote by convention. You could call it something else, but almost everyone uses origin. A repo can have several remotes (for example, origin and upstream when you work with forks).

# See the configured remotes and their URLs
git remote -v
# origin  https://github.com/usuario/repo.git (fetch)
# origin  https://github.com/usuario/repo.git (push)

# Add a remote named origin (when you started with git init)
git remote add origin https://github.com/usuario/repo.git

# Change the URL of an existing remote
git remote set-url origin https://github.com/usuario/otro-repo.git

# See detailed information about a remote
git remote show origin

# Remove a remote
git remote remove origin

Thinking that origin is a Git reserved word with a special meaning. It isn't: it's just a conventional name for the main remote. Another mistake is trying to run git push from a repo started with git init without first having added a remote with git remote add origin ....

"A remote is a version of the repository hosted somewhere else, typically a server like GitHub, that I sync my local copy with by doing push and pull. origin is simply the default name Git gives to the main remote, usually the one I cloned; it's an alias for a URL, not a magic word. I can have several remotes, for example origin and upstream when I work with forks."

Quick challenge

You started a repo with git init and want to upload it to an empty repo on GitHub. What do you need to do before you can run git push?

See answer

You need to add the remote: git remote add origin https://github.com/usuario/repo.git. When you start with git init, the repo has no remote configured (unlike git clone, which configures it for you). After adding it, you can run git push -u origin main.