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

[PATCH 2/2] git-init: set receive.guardCurrentBranch = true for non-bare repositories

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Mar 23, 2008, 20:44 UTC
Message-ID
<alpine.LSU.1.00.0803232144070.4353@racer.site>
In-Reply-To
<alpine.LSU.1.00.0803232142460.4353@racer.site>

When initializing a non-bare repositories, you most likely want to avoid pushing into the current branch (because a push does not touch the working tree at all).

Let's be nice to those users who have not read that part of the manual, and just outright refuse updating the current branch.

To be nice to those users who wrote that part of the manual, let's do that in git-init, so that existing repositories are not affected.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 Documentation/git-init.txt |    4 ++++
 builtin-init-db.c          |    1 +
 2 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/Documentation/git-init.txt b/Documentation/git-init.txt
index 62914da..03a4f0e 100644
--- a/Documentation/git-init.txt
+++ b/Documentation/git-init.txt
@@ -56,6 +56,10 @@ By default, the configuration flag receive.denyNonFastForwards is enabled
 in shared repositories, so that you cannot force a non fast-forwarding push
 into it.
 
+If you are initializing a non-bare repository, the config variable
+`receive.guardCurrentBranch` is set to true.  This avoids problems with
+pushing into the current branch, which does not touch the working tree.
+
 --
 
 
diff --git a/builtin-init-db.c b/builtin-init-db.c
index 4f93d03..4542054 100644
--- a/builtin-init-db.c
+++ b/builtin-init-db.c
@@ -243,6 +243,7 @@ static int create_default_files(const char *template_path)
 	else {
 		const char *work_tree = get_git_work_tree();
 		git_config_set("core.bare", "false");
+		git_config_set("receive.guardCurrentBranch", "true");
 		/* allow template config file to override the default */
 		if (log_all_ref_updates == -1)
 		    git_config_set("core.logallrefupdates", "true");
-- 
1.5.5.rc1.174.g591a9
Previous: Johannes SchindelinNext: Junio C Hamano
Message 2 of 11 in “Introduce receive.guardCurrentBranch”
  1. 1/2 Introduce receive.guardCurrentBranchJohannes Schindelin, Mar 23, 2008
  2. 2/2 git-init: set receive.guardCurrentBranch = true for non-bare repositoriesJohannes Schindelin, Mar 23, 2008
  3. Junio C HamanoMar 24, 2008
  4. Johannes SchindelinMar 24, 2008
  5. Junio C HamanoMar 24, 2008
  6. Johannes SchindelinMar 24, 2008
  7. Daniel BarkalowMar 24, 2008
  8. Johannes SchindelinMar 24, 2008
  9. Miklos VajnaMar 24, 2008
  10. Johannes SchindelinMar 24, 2008
  11. Miklos VajnaMar 24, 2008

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.