Git Reference ยท Remotes and Collaboration
git remote command
Reference for git remote: add, rename, remove, set-url, get-url, show, prune, update and set-head. Manage the short names that point to other repositories.
A remote is a short name (such as origin) for the URL of another repository, plus a refspec that says how its branches map to your remote-tracking branches. git remote lists and edits those names. All it changes is configuration in .git/config (the [remote "name"] sections) and, for remove, rename and prune, the remote-tracking refs under refs/remotes/<name>/.
Cloning creates a remote called origin for you. You can have as many remotes as you like, for example upstream for the original project of a fork.
git remote [-v | --verbose] git remote add [-f] [-t <branch>] [-m <master>] <name> <url> git remote rename | remove | set-url | get-url | show | prune | update | set-head | set-branches
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
| Subcommand | Description |
|---|---|
git remote |
List remote names. -v adds the fetch and push URLs. |
add <name> <url> |
Create a remote. -f fetches immediately; -t <branch> limits tracked branches; --tags or --no-tags controls tag fetching; --mirror=fetch|push sets up a mirror. |
rename <old> <new> |
Rename the remote, its tracking refs and its config sections. |
remove <name> (rm) |
Delete the remote, its tracking branches and its config. |
get-url [--push] [--all] <name> |
Print the URL; --push prints the push URL. |
set-url [--push] <name> <new> [<old>] |
Change a URL. --add adds a second one, --delete removes one. |
show [-n] <name> |
Describe the remote: URLs, HEAD branch, tracked branches, stale refs and push/pull configuration. Contacts the server unless -n. |
prune [-n] <name> |
Delete tracking branches whose upstream branch is gone. -n / --dry-run only lists them. |
update [-p] [<group>...] |
Fetch a remote or a group of remotes (remotes.<group> config). |
set-head <name> (-a | -d | <branch>) |
Set refs/remotes/<name>/HEAD; -a asks the server, -d deletes it. |
set-branches [--add] <name> <branch>... |
Replace (or add to) the list of branches the remote tracks. |
Remote names must be valid ref name components: no whitespace, and they cannot start with a dash.
Usage notes
- A remote's URL may be an HTTPS or SSH URL, a path to a local directory (as in the examples), or any other scheme from Git URLs.
url.<base>.insteadOfrewrites URLs on the fly. renamealso movesrefs/remotes/<old>/*and updatesbranch.<name>.remotefor branches that tracked the old remote.- Stale remote-tracking branches do not disappear by themselves. Use
git fetch --prune(orfetch.prune=true) orgit remote prune. - A separate push URL, set with
set-url --pushorremote.<name>.pushurl, lets you fetch from one place and push to another. git remote -vshows(fetch)and(push)lines for each remote; two push lines appear when a remote has several push URLs, and Git pushes to all of them.- Removing a remote does not delete anything on the server, only your local reference to it.
- The commands that talk to the network are fetch, pull, push and ls-remote.
Related
- git fetch, git push, git ls-remote, git clone, Refspecs
- Tutorial: Remotes, Forks and upstreams