Working with Remotes in Git
testYourself Git721
To be able to collaborate on any Git project, you need to know how to manage your remote repositories.
List remotes
To see which remote servers you have configured, you can run the git remote
command. It lists the shortnames of each remote handle you’ve specified.
Add remote
To add a new remote, use the git remote add
command in the directory your repository is stored at.
The command takes two arguments: a remote name (e.g. origin
) and a remote URL.
Rename remote
To change a remote's shortname, use the git remote rename
command in the directory your repository is stored at.
The command takes two arguments: the current shortname and the new shortname.
Remove remote
To remove the reference to the remote repository, use the git remote remove
command in the directory your repository is stored at.
The command takes one argument: the current shortname of the reference you want to delete.
Git clone
The git clone
command clones a repository into a newly created directory, creates remote-tracking branches for each branch in the cloned repository, and creates and checks out an initial branch that is forked from the cloned repository’s currently active branch.
If you clone a repository, the command automatically adds that remote repository under the name origin
.
Git fetch and git pull
The git fetch
only downloads the data to your local repo, it doesn’t automatically merge it with any of your work or modify what you’re currently working on. You have to merge it manually into your work when you’re ready.
The git pull
is a shorthand for the git fetch
(downloads the data to your local repo) followed by git merge
(join two or more development histories together).
Git push
The git push
command is used to upload local repository content to a remote repository.