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.
- 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.
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>.
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.
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.
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.
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>
- 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.
- Send current branch to <name>.
- Push <branch> to <name>.
- Using a colon in place of a branch name, will push all branches that exist in both the local and remote repositories.
- 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.
user:~/project$ git remote rename <name> <new> user:~/project$ git remote remove <name>
- Will change the name that is associated with the remote.
- Will remove the remote from the list repositories list.
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.