git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Teach "git remote add" a mirror mode

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Sep 2, 2007, 11:45 UTC
Message-ID
<Pine.LNX.4.64.0709021245040.28586@racer.site>

When using the "--mirror" option to "git remote add", the refs will not be stored in the refs/remotes/ namespace, but in refs/heads/.

This option probably only makes sense in a bare repository.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 Documentation/git-remote.txt |    6 +++++-
 git-remote.perl              |   10 +++++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/Documentation/git-remote.txt b/Documentation/git-remote.txt
index 61a6022..94b9f17 100644
--- a/Documentation/git-remote.txt
+++ b/Documentation/git-remote.txt
@@ -10,7 +10,7 @@ SYNOPSIS
 --------
 [verse]
 'git-remote'
-'git-remote' add [-t <branch>] [-m <branch>] [-f] <name> <url>
+'git-remote' add [-t <branch>] [-m <branch>] [-f] [--mirror] <name> <url>
 'git-remote' show <name>
 'git-remote' prune <name>
 'git-remote' update [group]
@@ -45,6 +45,10 @@ multiple branches without grabbing all branches.
 With `-m <master>` option, `$GIT_DIR/remotes/<name>/HEAD` is set
 up to point at remote's `<master>` branch instead of whatever
 branch the `HEAD` at the remote repository actually points at.
++
+In mirror mode, enabled with `--mirror`, the refs will not be stored
+in the 'refs/remotes/' namespace, but in 'refs/heads/'.  This option
+only makes sense in bare repositories.
 
 'show'::
 
diff --git a/git-remote.perl b/git-remote.perl
index 01cf480..e00b340 100755
--- a/git-remote.perl
+++ b/git-remote.perl
@@ -276,9 +276,13 @@ sub add_remote {
 	$git->command('config', "remote.$name.url", $url);
 	my $track = $opts->{'track'} || ["*"];
 
+	my $prefix = "refs/remotes/$name/";
+	if ($opts->{'mirror'}) {
+		$prefix = "refs/heads/";
+	}
 	for (@$track) {
 		$git->command('config', '--add', "remote.$name.fetch",
-			      "+refs/heads/$_:refs/remotes/$name/$_");
+			      "+refs/heads/$_:$prefix/$_");
 	}
 	if ($opts->{'fetch'}) {
 		$git->command('fetch', $name);
@@ -409,6 +413,10 @@ elsif ($ARGV[0] eq 'add') {
 			shift @ARGV;
 			next;
 		}
+		if ($opt eq '--mirror') {
+			$opts{'mirror'} = 1;
+			next;
+		}
 		add_usage();
 	}
 	if (@ARGV != 3) {
-- 
1.5.3.2.g46909
Next: Junio C Hamano
Message 1 of 5 in “Teach "git remote add" a mirror mode”
  1. Teach "git remote add" a mirror modeJohannes Schindelin, Sep 2, 2007
  2. Junio C HamanoSep 2, 2007
  3. Teach "git remote" a mirror modeJohannes Schindelin, Sep 2, 2007
  4. Junio C HamanoSep 3, 2007
  5. Johannes SchindelinSep 3, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.