Git: Working with remotes

Git remote is a kind of bookmark or url of a repository from which we can pull or push our code. This can be on our local computer or on a remote server like GitHub or GitLab.

We can simply call it remote repository. We can have multiple remote repository on internet for a single project. Some of them might be read only repositories and some of them might be readable and writable.

View remotes

To view available or configured remotes, we can use git remote command. This command will list out name all configured remotes.

Here, origin is a short name of a remote. Git stores a short name and the url for each remote. The default remote name that Git assign to a remote is origin.

To view remote’s short name with its url, use -v option.

If there are multiple remotes, you can see them all. For example,

So, here we can pull and push from multiple remotes, i.e. origin and gitlab.

Add a new remote

To add a new remote, we can simple use git remote add command. The exact syntax is, git remote add [shortname][url].

Now, new remote bitbucket is added. We can now pull and push to this new remote using shortname bitbucket.

Rename existing remote

Sometimes, we may need to update our remote’s shortname. We can simply specify git rename command. For example, to rename our bitbucket remote to gitlab,

Update remote url

To update existing remote’s url, we can use git remote set-url command. For example, to update our origin’s url to https://gitlab.com/example/demogit,

Remove a remote

We can remove an existing remote using git remote rm command. For example, to remove gitlab remote,

There are the basic commands of git remotes. Enjoy versioning!

You may also like...