Git Remotes in Five Minutes or Less
Tags: git, remote, intro, short
Published: 2020-04-08 17:07:47

---
title: Git Remotes in Five Minutes or Less
published: true
description: Quickly understand the difference between local and remote repositories.
tags: git, remote, intro, short
series: Git bit-by-bit
---
# Recap
So far in this series we've covered the basics what a git repository is. As well as how to manage git repositories in your local environment. In this entry, we're going to look at how you can take your work, and make it available on the internet.

# Vocabulary
1. Remote
  * A non-local location for a repository. Accessed via URL. Stored as a key-value pair, where a given name is the key and the URL is the value.
    *Note: A local repository may have many remotes.*

# Commands
```shell
user:~/project$ git remote add <name> <URL>
```
* When ran in an existing local repository, this command adds the URL to the list of remotes. Any branches from the remote repository, will follow a naming pattern of \<name\>/\<branch\>.
```shell
user:~/project$ git clone <URL>
```
* Creates a new repository containing the contents of the repository located at \<URL\>. Automatically adds the remote to the repositories list.
```shell
user:~/project$ git fetch
user:~/project$ git fetch <name>
```
* Retrieves information about remote repositories. The name of a remote can be provided to retrieve its history alone.
```shell
user:~/project$ git pull
user:~/project$ git pull <name>
user:~/project$ git pull <name> <branch>
```
* Retrieves information from remote repositories
* Attempts to merge remote branch into local branch. 
* If no remote name is provided, the default is used.
* If no branch name is provided, it will attempt to merge a remote branch with the same name as the locally active branch.
* Similar to **git merge** from the last entry, you can pass flags to the command to prevent automatically merging.
```shell
user:~/project$ git push
user:~/project$ git push <name>
user:~/project$ git push <name> <branch>
user:~/project$ git push <name> :
user:~/project$ git push <name> <branch>:<remote>
```
1. Send local changes to remote repository.
  * If no remote is specified, will attempt to update the remote for the current branch. You can use the **--all** flag to push all branches.
2. Send current branch to \<name\>.
3. Push \<branch\> to \<name\>.
3. Using a colon in place of a branch name, will push all branches that exist in both the local and remote repositories.
4. You can push local branches to remote branches with different names, by specifying the two, separated by a colon. Effectively merging your local branch with the remote branch, in the remote repository. 
```shell
user:~/project$ git remote rename <name> <new>
user:~/project$ git remote remove <name>
```
1. Will change the name that is associated with the remote.
2. Will remove the remote from the list repositories list.

# More Information
Remotes are arguably the most valuable feature of Git. They enable anyone to work on any number of projects at any given time or location. While the commands above will get you running with remotes. The real magic comes from the remote providers. They've made their hosting free and openly available to anyone with an internet connection. By doing so, they've fundamentally changed people's access to software and the information it provides. If you're not familiar already, I would strongly suggest you spend some time getting familiar with them and the people they work with.
* [Github](https://github.com/)
* [Create your first repo](https://help.github.com/en/github/getting-started-with-github/create-a-repo)
* [Connect with other contributors](https://help.github.com/en/github/getting-started-with-github/be-social)


---
Find me on [Twitter](https://twitter.com/FastFlowZ) | [LinkedIn](https://www.linkedin.com/in/dakota-lewallen/)
Sponsor me on [Github](https://github.com/iamflowz)
Like the article? [Buy me a coffee!](https://www.buymeacoffee.com/iamflowz)