threads / discuss / 13576

bare --init Vs --init bare

Subject: bare --init Vs --init bare

## tl;dr

12 messages between May 19, 2008 and May 29, 2008.

replies: 11people: 4as markdown or json

Luciano Rocha· May 19, 2008, 17:53 UTC · lore
Hello,

This is odd: $ git init --bare usage: git-init [-q | --quiet] [--template=<template-directory>] [--shared] $ git --bare init Initialized empty Git repository in /tmp/1/

My git version: $ git --version git version 1.5.5.1.318.gc99b

(Has two patches on top of origin's 377d9c409ffe0f0d994b929aeb94716139207b9d, setting default prefix in Makefile.)

Regards, Luciano Rocha

-- 
Luciano Rocha <luciano@eurotux.com>
Eurotux Informática, S.A. <http://www.eurotux.com/>
Santi Béjar· May 19, 2008, 19:32 UTC · re: Luciano Rocha · lore

Re: bare --init Vs --init bare

On Mon, May 19, 2008 at 7:53 PM, Luciano Rocha <luciano@eurotux.com> wrote:
>
> Hello,
>
Show 5 quoted lines
> This is odd:
> $ git init --bare
> usage: git-init [-q | --quiet] [--template=<template-directory>] [--shared]
> $ git --bare init
> Initialized empty Git repository in /tmp/1/

The first is a flag to the init subcommand (man git-init), and the other is a flag to git (man git).

See also:
http://www.google.com/search?q=%22git+init+--bare%22+%22git+--bare+init%22
or equivalent

http://kerneltrap.org/mailarchive/git/2007/10/15/344050 "should git command and git-command be equivalent?"

Santi
Show 16 quoted lines
>
> My git version:
> $ git --version
> git version 1.5.5.1.318.gc99b
>
> (Has two patches on top of origin's
> 377d9c409ffe0f0d994b929aeb94716139207b9d, setting default prefix in
> Makefile.)
>
> Regards,
> Luciano Rocha
>
> --
> Luciano Rocha <luciano@eurotux.com>
> Eurotux Informática, S.A. <http://www.eurotux.com/>
>
Luciano Rocha· May 19, 2008, 20:10 UTC · re: Santi Béjar · lore

Re: bare --init Vs --init bare

On Mon, May 19, 2008 at 09:32:21PM +0200, Santi Béjar wrote:
Show 23 quoted lines
> On Mon, May 19, 2008 at 7:53 PM, Luciano Rocha <luciano@eurotux.com> wrote:
> >
> > Hello,
> >
> 
> > This is odd:
> > $ git init --bare
> > usage: git-init [-q | --quiet] [--template=<template-directory>] [--shared]
> > $ git --bare init
> > Initialized empty Git repository in /tmp/1/
> 
> The first is a flag to the init subcommand (man git-init), and the
> other is a flag to git (man git).
> 
> See also:
> 
> http://www.google.com/search?q=%22git+init+--bare%22+%22git+--bare+init%22
> 
> or equivalent
> 
> http://kerneltrap.org/mailarchive/git/2007/10/15/344050
> "should git command and git-command be equivalent?"
> 
Ok, I understand.

Still, there's a --bare command to git clone, and I had only tried git init --bare, not the other form, and it always failed. Only today did I learn I could do a git --bare init, from a colleague of mine.

I'd suggest allowing git init --bare, or documenting the --bare init option.

Regards, Luciano Rocha

-- 
Luciano Rocha <luciano@eurotux.com>
Eurotux Informática, S.A. <http://www.eurotux.com/>
Luciano Rocha· May 20, 2008, 19:48 UTC · re: Luciano Rocha · lore

[PATCH] git-init: inform user of `git --bare init' option

Creation of a bare repository isn't consistent:

$ git init --bare usage: git-init [-q | --quiet] [--template=<template-directory>] [--shared] $ git --bare init Initialized empty Git repository in ...

Document the second option, and show an error informing of it if the user calls `git-init' with a `--bare' option.

Signed-off-by: Luciano Rocha <strange@nsk.pt>
---
 Documentation/git-init.txt |    2 ++
 builtin-init-db.c          |    2 ++
 2 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/Documentation/git-init.txt b/Documentation/git-init.txt
index b17ae84..bb87e58 100644
--- a/Documentation/git-init.txt
+++ b/Documentation/git-init.txt
@@ -84,6 +84,8 @@ Running `git-init` in an existing repository is safe. It will not overwrite
 things that are already there. The primary reason for rerunning `git-init`
 is to pick up newly added templates.
 
+For creating a bare repository, use the form `git --bare init`.
+
 Note that `git-init` is the same as `git-init-db`.  The command
 was primarily meant to initialize the object database, but over
 time it has become responsible for setting up the other aspects
diff --git a/builtin-init-db.c b/builtin-init-db.c
index a76f5d3..65454b1 100644
--- a/builtin-init-db.c
+++ b/builtin-init-db.c
@@ -334,6 +334,8 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
 			template_dir = arg+11;
 		else if (!strcmp(arg, "--shared"))
 			shared_repository = PERM_GROUP;
+		else if (!strcmp(arg, "--bare"))
+			die("Run `git --bare init' instead to create a bare repository");
 		else if (!prefixcmp(arg, "--shared="))
 			shared_repository = git_config_perm("arg", arg+9);
 		else if (!strcmp(arg, "-q") || !strcmp(arg, "--quiet"))
-- 
1.5.5.1.317.ge7bcb.dirty
Junio C Hamano· May 23, 2008, 06:02 UTC · re: Luciano Rocha · lore

Re: [PATCH] git-init: inform user of `git --bare init' option

Luciano Rocha <luciano@eurotux.com> writes:
Show 6 quoted lines
> Creation of a bare repository isn't consistent:
>
> $ git init --bare
> usage: git-init [-q | --quiet] [--template=<template-directory>] [--shared]
> $ git --bare init
> Initialized empty Git repository in ...

The examples do not demonstrate that "it isn't consistent". It just demonstrates that it is easy for people to forget that --bare option is an option to the "git" potty itself and not an option to "git init".

Show 13 quoted lines
> diff --git a/builtin-init-db.c b/builtin-init-db.c
> index a76f5d3..65454b1 100644
> --- a/builtin-init-db.c
> +++ b/builtin-init-db.c
> @@ -334,6 +334,8 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
>  			template_dir = arg+11;
>  		else if (!strcmp(arg, "--shared"))
>  			shared_repository = PERM_GROUP;
> +		else if (!strcmp(arg, "--bare"))
> +			die("Run `git --bare init' instead to create a bare repository");
>  		else if (!prefixcmp(arg, "--shared="))
>  			shared_repository = git_config_perm("arg", arg+9);
>  		else if (!strcmp(arg, "-q") || !strcmp(arg, "--quiet"))

Given that you are adding a special case support for "git init --bare" anyway, a better approach to help people out of this easy confusion (and we have to admit that the confusion is very easy!) would be to make "git init --bare" pretend/behave as if the user said "git --bare init", don't you think?

Luciano Rocha· May 23, 2008, 14:24 UTC · re: Junio C Hamano · lore

Re: [PATCH] git-init: inform user of `git --bare init' option

On Thu, May 22, 2008 at 11:02:59PM -0700, Junio C Hamano wrote:
Show 12 quoted lines
> Luciano Rocha <luciano@eurotux.com> writes:
> 
> > Creation of a bare repository isn't consistent:
> >
> > $ git init --bare
> > usage: git-init [-q | --quiet] [--template=<template-directory>] [--shared]
> > $ git --bare init
> > Initialized empty Git repository in ...
> 
> The examples do not demonstrate that "it isn't consistent".  It just
> demonstrates that it is easy for people to forget that --bare option is an
> option to the "git" potty itself and not an option to "git init".

Well, "git --help init" works the same as "git init --help", so "--bare" not working depending on its position isn't very consistent...

<patch snipped>
Show 5 quoted lines
> Given that you are adding a special case support for "git init --bare"
> anyway, a better approach to help people out of this easy confusion (and
> we have to admit that the confusion is very easy!) would be to make "git
> init --bare" pretend/behave as if the user said "git --bare init", don't
> you think?

Yes, but this was easy for me to do. The proper way, however, will take me more time.

-- 
Luciano Rocha <luciano@eurotux.com>
Eurotux Informática, S.A. <http://www.eurotux.com/>
Luciano Rocha· May 28, 2008, 18:51 UTC · re: Junio C Hamano · lore

[PATCH] git-init: treat option `--bare'

Currently, passing the `--bare' option to git-init proper doesn't work, and gives no indication that `git --bare init' would work instead:

$ git init --bare usage: git-init [-q | --quiet] [--template=<template-directory>] [--shared]

Treat the `--bare' option internally in builtin-init-db.
Also, fix the usage string, synchronising it with the synopsis in the
documentation.
---
 Documentation/git-init.txt |    7 ++++++-
 builtin-init-db.c          |    9 +++++++--
 2 files changed, 13 insertions(+), 3 deletions(-)
Parsing the --bare option correctly (AFAICS) was easier than I expected.
diff --git a/Documentation/git-init.txt b/Documentation/git-init.txt
index b17ae84..b48c312 100644
--- a/Documentation/git-init.txt
+++ b/Documentation/git-init.txt
@@ -8,7 +8,7 @@ git-init - Create an empty git repository or reinitialize an existing one
 
 SYNOPSIS
 --------
-'git-init' [-q | --quiet] [--template=<template_directory>] [--shared[=<permissions>]]
+'git-init' [-q | --quiet] [--bare] [--template=<template_directory>] [--shared[=<permissions>]]
 
 
 OPTIONS
@@ -20,6 +20,11 @@ OPTIONS
 
 Only print error and warning messages, all other output will be suppressed.
 
+--bare::
+
+Create a bare repository. If GIT_DIR environment is not set, it is set to the
+current working directory.
+
 --template=<template_directory>::
 
 Provide the directory from which templates will be used.  The default template
diff --git a/builtin-init-db.c b/builtin-init-db.c
index d8bdf92..e23b843 100644
--- a/builtin-init-db.c
+++ b/builtin-init-db.c
@@ -364,7 +364,7 @@ static int guess_repository_type(const char *git_dir)
 }
 
 static const char init_db_usage[] =
-"git-init [-q | --quiet] [--template=<template-directory>] [--shared]";
+"git-init [-q | --quiet] [--bare] [--template=<template-directory>] [--shared[=<permissions>]]";
 
 /*
  * If you want to, you can share the DB area with any number of branches.
@@ -383,7 +383,12 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
 		const char *arg = argv[1];
 		if (!prefixcmp(arg, "--template="))
 			template_dir = arg+11;
-		else if (!strcmp(arg, "--shared"))
+		else if (!strcmp(arg, "--bare")) {
+			static char git_dir[PATH_MAX+1];
+			is_bare_repository_cfg = 1;
+			setenv(GIT_DIR_ENVIRONMENT, getcwd(git_dir,
+						sizeof(git_dir)), 0);
+		} else if (!strcmp(arg, "--shared"))
 			shared_repository = PERM_GROUP;
 		else if (!prefixcmp(arg, "--shared="))
 			shared_repository = git_config_perm("arg", arg+9);
-- 
1.5.6.rc0.41.gabae7.dirty
Luciano Rocha· May 28, 2008, 18:53 UTC · re: Luciano Rocha · lore

Re: [PATCH] git-init: treat option `--bare'

Currently, passing the `--bare' option to git-init proper doesn't work, and gives no indication that `git --bare init' would work instead:

$ git init --bare usage: git-init [-q | --quiet] [--template=<template-directory>] [--shared]

Treat the `--bare' option internally in builtin-init-db.

Also, fix the usage string, synchronising it with the synopsis in the documentation.

Signed-off-by: Luciano Rocha <strange@nsk.pt>
---
 Documentation/git-init.txt |    7 ++++++-
 builtin-init-db.c          |    9 +++++++--
 2 files changed, 13 insertions(+), 3 deletions(-)
Parsing the --bare option correctly (AFAICS) was easier than I expected.
Sorry, forgot the Signed-off-by line.
diff --git a/Documentation/git-init.txt b/Documentation/git-init.txt
index b17ae84..b48c312 100644
--- a/Documentation/git-init.txt
+++ b/Documentation/git-init.txt
@@ -8,7 +8,7 @@ git-init - Create an empty git repository or reinitialize an existing one
 
 SYNOPSIS
 --------
-'git-init' [-q | --quiet] [--template=<template_directory>] [--shared[=<permissions>]]
+'git-init' [-q | --quiet] [--bare] [--template=<template_directory>] [--shared[=<permissions>]]
 
 
 OPTIONS
@@ -20,6 +20,11 @@ OPTIONS
 
 Only print error and warning messages, all other output will be suppressed.
 
+--bare::
+
+Create a bare repository. If GIT_DIR environment is not set, it is set to the
+current working directory.
+
 --template=<template_directory>::
 
 Provide the directory from which templates will be used.  The default template
diff --git a/builtin-init-db.c b/builtin-init-db.c
index d8bdf92..e23b843 100644
--- a/builtin-init-db.c
+++ b/builtin-init-db.c
@@ -364,7 +364,7 @@ static int guess_repository_type(const char *git_dir)
 }
 
 static const char init_db_usage[] =
-"git-init [-q | --quiet] [--template=<template-directory>] [--shared]";
+"git-init [-q | --quiet] [--bare] [--template=<template-directory>] [--shared[=<permissions>]]";
 
 /*
  * If you want to, you can share the DB area with any number of branches.
@@ -383,7 +383,12 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
 		const char *arg = argv[1];
 		if (!prefixcmp(arg, "--template="))
 			template_dir = arg+11;
-		else if (!strcmp(arg, "--shared"))
+		else if (!strcmp(arg, "--bare")) {
+			static char git_dir[PATH_MAX+1];
+			is_bare_repository_cfg = 1;
+			setenv(GIT_DIR_ENVIRONMENT, getcwd(git_dir,
+						sizeof(git_dir)), 0);
+		} else if (!strcmp(arg, "--shared"))
 			shared_repository = PERM_GROUP;
 		else if (!prefixcmp(arg, "--shared="))
 			shared_repository = git_config_perm("arg", arg+9);
-- 
1.5.6.rc0.41.gabae7.dirty
Junio C Hamano· May 29, 2008, 00:55 UTC · re: Luciano Rocha · lore

Re: [PATCH] git-init: treat option `--bare'

Luciano Rocha <luciano@eurotux.com> writes:
Show 12 quoted lines
> Currently, passing the `--bare' option to git-init proper doesn't work, and
> gives no indication that `git --bare init' would work instead:
>
> $ git init --bare
> usage: git-init [-q | --quiet] [--template=<template-directory>] [--shared]
>
> Treat the `--bare' option internally in builtin-init-db.
>
> Also, fix the usage string, synchronising it with the synopsis in the
> documentation.
>
> Signed-off-by: Luciano Rocha <strange@nsk.pt>

It could be argued that this kind of "special casing to help common mistake situation" would in the long run hamper the new users in understanding what --bare means, because one who uses "git init --bare" will not realize that --bare is an option to "git" potty in general and can be given when invoking other git commands. On the other hand, many commands do work sensibly inside a bare repository already, and "init" is truly special in that it cannot inspect the surroundings to guess if the user wants to create a bare repository or one with a work-tree because there isn't a repository yet. In that sense, probably people not learning "git --bare" is not such a loss after all.

In general, I am not particularly fond of this kind of special casing, but initializing a bare repository would be a common enough operation that I personally think it is probably Ok to take this as an exception.

Opinions?  Breakages?
Luciano Rocha· May 29, 2008, 09:10 UTC · re: Junio C Hamano · lore

Re: [PATCH] git-init: treat option `--bare'

On Wed, May 28, 2008 at 05:55:46PM -0700, Junio C Hamano wrote:
Show 32 quoted lines
> Luciano Rocha <luciano@eurotux.com> writes:
> 
> > Currently, passing the `--bare' option to git-init proper doesn't work, and
> > gives no indication that `git --bare init' would work instead:
> >
> > $ git init --bare
> > usage: git-init [-q | --quiet] [--template=<template-directory>] [--shared]
> >
> > Treat the `--bare' option internally in builtin-init-db.
> >
> > Also, fix the usage string, synchronising it with the synopsis in the
> > documentation.
> >
> > Signed-off-by: Luciano Rocha <strange@nsk.pt>
> 
> It could be argued that this kind of "special casing to help common
> mistake situation" would in the long run hamper the new users in
> understanding what --bare means, because one who uses "git init --bare"
> will not realize that --bare is an option to "git" potty in general and
> can be given when invoking other git commands.  On the other hand, many
> commands do work sensibly inside a bare repository already, and "init" is
> truly special in that it cannot inspect the surroundings to guess if the
> user wants to create a bare repository or one with a work-tree because
> there isn't a repository yet.  In that sense, probably people not learning
> "git --bare" is not such a loss after all.
> 
> In general, I am not particularly fond of this kind of special casing, but
> initializing a bare repository would be a common enough operation that I
> personally think it is probably Ok to take this as an exception.
> 
> Opinions?  Breakages?
> 

Personally, my first experience with bare repositories, was when I decided to have local mirrors of several projects. As I weren't going to do work over then, I considered copies without a checkout. Reading the documentation for git-clone, I found the '--bare' option, and found that the commands that I mattered about worked transparently (log, diff, archive).

Much later, when trying to create a public mirror of some of my projects, I tried to create a bare copy. However, as I didn't have access from the remote server to my working copy, I had to push my changes to the remote server.

But 'git init --bare' didn't work, so I resorted to: mirror$ git init personal$ git push mirror:copy mirror$ git clone --bare copy public

Only some time later, in a discussion with a friend, did I learn that 'git --bare init' worked (and thus this thread was started).

In my defence, the usage displayed when running just "git" hides the '--bare' option, as my terminals usually have 24 lines.

And the transparently way that the other commands I cared about worked inside a bare repository eliminated any need of mine to search for a way to specify that I was working with a bare repository to all git commands.

All in all, you are right when you say that 'this kind of "special casing" ... would in the long run hamper the new users ... [by not realizing ] that --bare is an option to "git" potty in general', as is attested by my ignorance of it. But as there is a valid reason for the '--bare' option to git-clone, there is one for git-init.

But the '--bare' option for "git" must be at least mentioned in the documentation for those two commands.

-- 
Luciano Rocha <luciano@eurotux.com>
Eurotux Informática, S.A. <http://www.eurotux.com/>
Johannes Schindelin· May 29, 2008, 13:51 UTC · re: Junio C Hamano · lore

Re: [PATCH] git-init: treat option `--bare'

Hi,
On Wed, 28 May 2008, Junio C Hamano wrote:
> In general, I am not particularly fond of this kind of special casing, 
> but initializing a bare repository would be a common enough operation 
> that I personally think it is probably Ok to take this as an exception.

I like the Perl way (having multiple options to do the same thing), and do not like the Python way ("there is only one way to do one thing").

> Opinions?  Breakages?

I like the intent of the patch. It will definitely make initializing bare Git repositories easier for new users.

Also keep in mind that "git --bare <some-command-other-than-init" is _really_ rare, at least in my experience. I had to use it exactly _twice_ since I started using Git.

Ciao, Dscho

Junio C Hamano· May 29, 2008, 18:31 UTC · re: Johannes Schindelin · lore

Re: [PATCH] git-init: treat option `--bare'

Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> Also keep in mind that "git --bare <some-command-other-than-init" is 
> _really_ rare, at least in my experience.  I had to use it exactly _twice_ 
> since I started using Git.

Exactly. That is really the contributing factor that I am in favor of this (perhaps redundant from theoretical point of view) addition.

← back to recent threads