git-remote.txt 8.2 KB
Newer Older
1
git-remote(1)
2
=============
3 4 5

NAME
----
6
git-remote - Manage set of tracked repositories
7 8 9 10 11


SYNOPSIS
--------
[verse]
12
'git remote' [-v | --verbose]
J
Jean-Noël Avila 已提交
13
'git remote add' [-t <branch>] [-m <master>] [-f] [--[no-]tags] [--mirror=(fetch|push)] <name> <url>
M
Miklos Vajna 已提交
14
'git remote rename' <old> <new>
15
'git remote remove' <name>
16
'git remote set-head' <name> (-a | --auto | -d | --delete | <branch>)
17
'git remote set-branches' [--add] <name> <branch>...
B
Ben Boeckel 已提交
18
'git remote get-url' [--push] [--all] <name>
I
Ilari Liusvaara 已提交
19 20 21
'git remote set-url' [--push] <name> <newurl> [<oldurl>]
'git remote set-url --add' [--push] <name> <newurl>
'git remote set-url --delete' [--push] <name> <url>
22 23
'git remote' [-v | --verbose] 'show' [-n] <name>...
'git remote prune' [-n | --dry-run] <name>...
24
'git remote' [-v | --verbose] 'update' [-p | --prune] [(<group> | <remote>)...]
25 26 27 28 29 30 31

DESCRIPTION
-----------

Manage the set of repositories ("remotes") whose branches you track.


32 33 34 35 36 37
OPTIONS
-------

-v::
--verbose::
	Be a little more verbose and show remote url after name.
J
Jean-Noël Avila 已提交
38
	NOTE: This must be placed between `remote` and subcommand.
39 40


41 42 43 44 45 46 47 48
COMMANDS
--------

With no arguments, shows a list of existing remotes.  Several
subcommands are available to perform operations on the remotes.

'add'::

J
Jean-Noël Avila 已提交
49
Add a remote named <name> for the repository at
50 51
<url>.  The command `git fetch <name>` can then be used to create and
update remote-tracking branches <name>/<branch>.
52 53 54 55
+
With `-f` option, `git fetch <name>` is run immediately after
the remote information is set up.
+
56 57 58 59 60 61
With `--tags` option, `git fetch <name>` imports every tag from the
remote repository.
+
With `--no-tags` option, `git fetch <name>` does not import tags from
the remote repository.
+
62 63 64
By default, only tags on fetched branches are imported
(see linkgit:git-fetch[1]).
+
65 66
With `-t <branch>` option, instead of the default glob
refspec for the remote to track all branches under
67
the `refs/remotes/<name>/` namespace, a refspec to track only `<branch>`
68
is created.  You can give more than one `-t <branch>` to track
69
multiple branches without grabbing all branches.
70
+
71
With `-m <master>` option, a symbolic-ref `refs/remotes/<name>/HEAD` is set
72
up to point at remote's `<master>` branch. See also the set-head command.
73
+
74
When a fetch mirror is created with `--mirror=fetch`, the refs will not
75 76 77 78 79
be stored in the 'refs/remotes/' namespace, but rather everything in
'refs/' on the remote will be directly mirrored into 'refs/' in the
local repository. This option only makes sense in bare repositories,
because a fetch would overwrite any local commits.
+
80 81
When a push mirror is created with `--mirror=push`, then `git push`
will always behave as if `--mirror` was passed.
82

M
Miklos Vajna 已提交
83 84
'rename'::

85
Rename the remote named <old> to <new>. All remote-tracking branches and
M
Miklos Vajna 已提交
86
configuration settings for the remote are updated.
87 88 89 90
+
In case <old> and <new> are the same, and <old> is a file under
`$GIT_DIR/remotes` or `$GIT_DIR/branches`, the remote is converted to
the configuration file format.
M
Miklos Vajna 已提交
91

92
'remove'::
93 94
'rm'::

95
Remove the remote named <name>. All remote-tracking branches and
96 97
configuration settings for the remote are removed.

98 99
'set-head'::

100 101
Sets or deletes the default branch (i.e. the target of the
symbolic-ref `refs/remotes/<name>/HEAD`) for
102 103 104 105 106 107
the named remote. Having a default branch for a remote is not required,
but allows the name of the remote to be specified in lieu of a specific
branch. For example, if the default branch for `origin` is set to
`master`, then `origin` may be specified wherever you would normally
specify `origin/master`.
+
108
With `-d` or `--delete`, the symbolic ref `refs/remotes/<name>/HEAD` is deleted.
109
+
110
With `-a` or `--auto`, the remote is queried to determine its `HEAD`, then the
111
symbolic-ref `refs/remotes/<name>/HEAD` is set to the same branch. e.g., if the remote
J
Jean-Noël Avila 已提交
112
`HEAD` is pointed at `next`, `git remote set-head origin -a` will set
113
the symbolic-ref `refs/remotes/origin/HEAD` to `refs/remotes/origin/next`. This will
114 115 116
only work if `refs/remotes/origin/next` already exists; if not it must be
fetched first.
+
J
Jean-Noël Avila 已提交
117 118
Use `<branch>` to set the symbolic-ref `refs/remotes/<name>/HEAD` explicitly. e.g., `git
remote set-head origin master` will set the symbolic-ref `refs/remotes/origin/HEAD` to
119 120 121 122
`refs/remotes/origin/master`. This will only work if
`refs/remotes/origin/master` already exists; if not it must be fetched first.
+

J
Jonathan Nieder 已提交
123 124 125 126 127 128 129
'set-branches'::

Changes the list of branches tracked by the named remote.
This can be used to track a subset of the available remote branches
after the initial setup for a remote.
+
The named branches will be interpreted as if specified with the
J
Jean-Noël Avila 已提交
130
`-t` option on the `git remote add` command line.
J
Jonathan Nieder 已提交
131 132 133 134
+
With `--add`, instead of replacing the list of currently tracked
branches, adds to that list.

B
Ben Boeckel 已提交
135 136 137 138 139
'get-url'::

Retrieves the URLs for a remote. Configurations for `insteadOf` and
`pushInsteadOf` are expanded here. By default, only the first URL is listed.
+
140
With `--push`, push URLs are queried rather than fetch URLs.
B
Ben Boeckel 已提交
141
+
142
With `--all`, all URLs for the remote will be listed.
B
Ben Boeckel 已提交
143

I
Ilari Liusvaara 已提交
144 145
'set-url'::

146
Changes URLs for the remote. Sets first URL for remote <name> that matches
I
Ilari Liusvaara 已提交
147
regex <oldurl> (first URL if no <oldurl> is given) to <newurl>. If
148
<oldurl> doesn't match any URL, an error occurs and nothing is changed.
I
Ilari Liusvaara 已提交
149
+
150
With `--push`, push URLs are manipulated instead of fetch URLs.
I
Ilari Liusvaara 已提交
151
+
152
With `--add`, instead of changing existing URLs, new URL is added.
I
Ilari Liusvaara 已提交
153
+
154
With `--delete`, instead of changing existing URLs, all URLs matching
155 156 157 158 159 160 161 162 163 164
regex <url> are deleted for remote <name>.  Trying to delete all
non-push URLs is an error.
+
Note that the push URL and the fetch URL, even though they can
be set differently, must still refer to the same place.  What you
pushed to the push URL should be what you would see if you
immediately fetched from the fetch URL.  If you are trying to
fetch from one place (e.g. your upstream) and push to another (e.g.
your publishing repository), use two separate remotes.

I
Ilari Liusvaara 已提交
165

166
'show'::
167

168
Gives some information about the remote <name>.
S
Sam Vilain 已提交
169 170 171
+
With `-n` option, the remote heads are not queried first with
`git ls-remote <name>`; cached information is used instead.
172 173 174

'prune'::

175 176 177 178 179 180 181 182
Deletes stale references associated with <name>. By default, stale
remote-tracking branches under <name> are deleted, but depending on
global configuration and the configuration of the remote we might even
prune local tags that haven't been pushed there. Equivalent to `git
fetch --prune <name>`, except that no new references will be fetched.
+
See the PRUNING section of linkgit:git-fetch[1] for what it'll prune
depending on various configuration.
S
Sam Vilain 已提交
183
+
J
Jean-Noël Avila 已提交
184
With `--dry-run` option, report what branches would be pruned, but do not
185
actually prune them.
186 187 188

'update'::

189
Fetch updates for remotes or remote groups in the repository as defined by
J
Jean-Noël Avila 已提交
190
`remotes.<group>`. If neither group nor remote is specified on the command line,
191
the configuration parameter remotes.default will be used; if
S
Sergei Organov 已提交
192
remotes.default is not defined, all remotes which do not have the
J
Jean-Noël Avila 已提交
193
configuration parameter `remote.<name>.skipDefaultUpdate` set to true will
194
be updated.  (See linkgit:git-config[1]).
195
+
196
With `--prune` option, run pruning against all the remotes that are updated.
197

198 199 200 201

DISCUSSION
----------

202 203
The remote configuration is achieved using the `remote.origin.url` and
`remote.origin.fetch` configuration variables.  (See
204
linkgit:git-config[1]).
205

206
EXAMPLES
207 208
--------

209 210
* Add a new remote, fetch, and check out a branch from it
+
211 212 213 214
------------
$ git remote
origin
$ git branch -r
215 216 217
  origin/HEAD -> origin/master
  origin/master
$ git remote add staging git://git.kernel.org/.../gregkh/staging.git
218 219
$ git remote
origin
220 221 222 223 224 225 226
staging
$ git fetch staging
...
From git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging
 * [new branch]      master     -> staging/master
 * [new branch]      staging-linus -> staging/staging-linus
 * [new branch]      staging-next -> staging/staging-next
227
$ git branch -r
228 229 230 231 232
  origin/HEAD -> origin/master
  origin/master
  staging/master
  staging/staging-linus
  staging/staging-next
233
$ git switch -c staging staging/master
234 235 236
...
------------

237
* Imitate 'git clone' but track only selected branches
238 239 240 241 242 243 244 245 246 247
+
------------
$ mkdir project.git
$ cd project.git
$ git init
$ git remote add -f -t master -m master origin git://example.com/git.git/
$ git merge origin
------------


248
SEE ALSO
249
--------
250 251 252
linkgit:git-fetch[1]
linkgit:git-branch[1]
linkgit:git-config[1]
253 254 255

GIT
---
256
Part of the linkgit:git[1] suite