GIT-REMOTE(1)

๐ŸŽ€ GIT-REMOTE(1) ๐ŸŽ€

okay bestie, welcome to the git-remote page, straight outta the Git Manual ๐Ÿ’– this is the one that manages your set of tracked repositories โ€” aka the people (repos) you're in a situationship with.


โœจ SYNOPSIS โœจ

git remote [-v | --verbose]
git remote add [-t <branch>] [-m <master>] [-f] [--[no-]tags] [--mirror=(fetch|push)] <name> <URL>
git remote rename [--[no-]progress] <old> <new>
git remote remove <name>
git remote set-head <name> (-a | --auto | -d | --delete | <branch>)
git remote set-branches [--add] <name> <branch>...
git remote get-url [--push] [--all] <name>
git remote set-url [--push] <name> <newurl> [<oldurl>]
git remote set-url --add [--push] <name> <newurl>
git remote set-url --delete [--push] <name> <URL>
git remote [-v | --verbose] show [-n] <name>...
git remote prune [-n | --dry-run] <name>...
git remote [-v | --verbose] update [-p | --prune] [(<group> | <remote>)...]

๐Ÿ’… DESCRIPTION ๐Ÿ’…

She manages the set of repositories (called "remotes", iykyk) whose branches you track. that's the whole vibe. your little black book of repos ๐Ÿ“–โœจ


๐Ÿฆ‹ OPTIONS ๐Ÿฆ‹

  • -v, --verbose โ€” be a little more verbose, bestie: shows the remote url right after the name. and for promisor remotes, it also shows which filters (blob:none etc.) are configured ๐Ÿ‘€. NOTE: this has to be placed between remote and the subcommand โ€” like, position matters, no cap.

๐Ÿ‘‘ COMMANDS ๐Ÿ‘‘

With no arguments at all, she just shows you a list of the remotes you already have. but there are several subcommands for actually doing stuff to them ๐Ÿ’…

๐Ÿ“ add

Adds a remote named <name> for the repository at <URL>. after that you can run git fetch <name> to create and update remote-tracking branches <name>/<branch> โ€” cute!

  • With the -f option, git fetch <name> is run immediately after the remote info is set up. instant gratification โœจ
  • With --tags, git fetch <name> imports every tag from the remote repository.
  • With --no-tags, git fetch <name> does not import tags from the remote repository.
  • By default, only tags on fetched branches are imported (see git-fetch(1)).

With the -t <branch> option, instead of the default glob refspec where the remote tracks all branches under the refs/remotes/<name>/ namespace, a refspec tracking only <branch> is created. you can hand her more than one -t <branch> to track multiple branches without grabbing all of them ๐ŸŽฏ

With the -m <master> option, a symbolic-ref refs/remotes/<name>/HEAD is set up to point at the remote's <master> branch. also peep the set-head command, they're besties.

โš ๏ธ okay so when a fetch mirror is created with --mirror=fetch, the refs are not stored in the refs/remotes/ namespace โ€” instead, everything in refs/ on the remote gets directly mirrored into refs/ in the local repository. this option only makes sense in bare repositories, because a fetch would overwrite any local commits ๐Ÿ˜ญ like, fr fr, careful.

When a push mirror is created with --mirror=push, then git push will always behave as if --mirror was passed. she said periodt ๐Ÿ’€

๐ŸŒธ rename

Renames the remote named <old> to <new>. all remote-tracking branches and configuration settings for the remote get updated too ๐Ÿซถ

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. glow-up moment โœจ

๐ŸŒˆ remove, rm

Removes the remote named <name>. all its remote-tracking branches and configuration settings are removed as well. it's giving blocking them ๐Ÿšซ

โญ set-head

Sets or deletes the default branch for the named remote โ€” that's the target of the symbolic-ref refs/remotes/<name>/HEAD. having a default branch for a remote isn't required, but it lets you specify the remote's name instead of a specific branch. for example, if the default branch for origin is set to master, then origin may be specified wherever you'd normally specify origin/master. iconic shortcut behavior ๐Ÿ‘‘

  • With -d or --delete, the symbolic ref refs/remotes/<name>/HEAD is deleted.
  • With -a or --auto, the remote is queried to figure out its HEAD, then the symbolic-ref refs/remotes/<name>/HEAD is set to the same branch. e.g., if the remote HEAD is pointed at next, git remote set-head origin -a will set the symbolic-ref refs/remotes/origin/HEAD to refs/remotes/origin/next. โš ๏ธ this will only work if refs/remotes/origin/next already exists โ€” if not, it must be fetched first!
  • 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 refs/remotes/origin/master. โš ๏ธ again, this only works if refs/remotes/origin/master already exists โ€” if not, it must be fetched first.

๐Ÿงš set-branches

Changes the list of branches tracked by the named remote. this is how you track a subset of the available remote branches after the initial setup for a remote โ€” very curated of you ๐Ÿ’…

The named branches get interpreted as if they were specified with the -t option on the git remote add command line.

  • With --add, instead of replacing the list of currently tracked branches, she adds to that list. more is more ๐ŸŽ€

๐Ÿ’œ get-url

Retrieves the URLs for a remote. configurations for insteadOf and pushInsteadOf are expanded here. by default, only the first URL is listed.

  • With --push, push URLs are queried rather than fetch URLs.
  • With --all, all URLs for the remote are listed. all of them. the whole collection ๐Ÿฆ‹

๐Ÿ”ฅ set-url

Changes URLs for the remote. sets the first URL for remote <name> that matches regex <oldurl> (first URL if no <oldurl> is given) to <newurl>. if <oldurl> doesn't match any URL, an error occurs and nothing is changed ๐Ÿ™ˆ

  • With --push, push URLs are manipulated instead of fetch URLs.
  • With --add, instead of changing existing URLs, a new URL is added.
  • With --delete, instead of changing existing URLs, all URLs matching regex <URL> are deleted for remote <name>. โš ๏ธ trying to delete all non-push URLs is an error.
๐Ÿ’€ important bestie: 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'd see if you immediately fetched from the fetch URL. if you're trying to fetch from one place (e.g. your upstream) and push to another (e.g. your publishing repository), use two separate remotes. don't make it weird.

๐Ÿซถ show

Gives you some information about the remote <name>. spill the tea โ˜•

  • With the -n option, the remote heads are not queried first with git ls-remote <name>; cached information is used instead. no cap, it's faster.

๐Ÿ’€ prune

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 git-fetch(1) for what it'll prune depending on various configuration.

  • With the --dry-run option, she reports what branches would be pruned, but does not actually prune them. window shopping ๐Ÿ›๏ธ

๐Ÿงš update

Fetches updates for remotes or remote groups in the repository as defined by remotes.<group>. if neither group nor remote is specified on the command line, the configuration parameter remotes.default is used; if remotes.default isn't defined, all remotes which do not have the configuration parameter remote.<name>.skipDefaultUpdate set to true will be updated. (See git-config(1)).

  • With the --prune option, run pruning against all the remotes that are updated. two birds, one stone ๐Ÿช„

๐ŸŒŸ DISCUSSION ๐ŸŒŸ

The remote configuration is achieved using the remote.origin.url and remote.origin.fetch configuration variables. (See git-config(1)). that's the whole lore drop ๐Ÿ“š


โญ EXIT STATUS โญ

  • On success, the exit status is 0. slay ๐Ÿ’–
  • When subcommands such as add, rename, and remove can't find the remote in question, the exit status is 2.
  • When the remote already exists, the exit status is 3.
  • On any other error, the exit status may be any other non-zero value.

๐ŸŽ€ EXAMPLES ๐ŸŽ€

  • Add a new remote, fetch, and check out a branch from it
$ git remote
origin
$ git branch -r
  origin/HEAD -> origin/master
  origin/master
$ git remote add staging git://git.kernel.org/.../gregkh/staging.git
$ git remote
origin
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
$ git branch -r
  origin/HEAD -> origin/master
  origin/master
  staging/master
  staging/staging-linus
  staging/staging-next
$ git switch -c staging staging/master
...
  • Imitate git clone but track only selected branches โ€” the โœจcuratedโœจ clone experience
$ 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

๐Ÿฆ‹ SEE ALSO ๐Ÿฆ‹

git-fetch(1) ยท git-branch(1) ยท git-config(1) โ€” go read those next, bestie, they're literally so good ๐Ÿซถ


๐Ÿ‘‘ GIT ๐Ÿ‘‘

Part of the git(1) suite ๐Ÿ’œ


and that's the whole page, bestie! ๐ŸŽ€ this was Git 2.56.0, dated 2026-09-27 โ€” mwah, go forth and remote responsibly โœจ๐Ÿ’…

๐Ÿ“ฆ where this page comes from