What is a git remote?

A remote is simply a URI to another git repository that has been labeled with a name in the local repository. You can clone this remote (i.e. other repository), fetch commits from it, push your own commits to it, push branches and tags to it, etc.

By default, Git creates a remote for you called “origin” when you use git clone. This can sometimes lead to confusion when people are learning Git . The word “origin” is not a reserved Git word, nor part of a command.

git push origin my-branch

In fact, “origin” in the above is just a parameter to git push, and it specifies which remote to push to.

To see all the remotes you’ve set up in your repository, use the following command:

git remote -v

Getting commits/information from a remote

The remote name can be used to get information about branches that were fetched from the remote. You can reference any branch in a remote using the format:

[remote-name]/[branch-name]

Be sure to git fetch [remote-name] in order to have the latest info about the objects in the remote. For example, if you have added a remote called “upstream” you could do something like this to see the changes in a commit on a branch of the upstream remote:

git fetch upstream
git show upstream/jimmys-special-branch~7

Remember that the commits and files in a remote on your local machine have been all copied from the remote git repository when you did git fetch. The “remote” in your local repository is just a static copy of what at the remote URL when you last did git fetch. You can see all the commits, check them out, etc., from a remote, even when there’s no network connection to the URL of the remote. In particular:

git checkout does not use an internet connection

Sometimes I’ve observed a bit of confusion about this.

Scope when removing remotes
It can be a bit scary the first time or two using git remote rm, etc. Note that you can use git remote add and git fetch to set up a remote again (given the URL) if you’ve gone a bit too delete-happy. Adding/removing remotes in your local repository does not change anything on the remote itself.
Is Github a remote?
Github is merely an online platform that provides an interface to work with Git repositories. Repositories hosted on Github can be added as remotes to a local repository just like any other Git repositories.