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

Re: receive.denyCurrentBranch

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 8, 2009, 06:43 UTC
Message-ID
<7vwsc11la3.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<20090208042910.19079.qmail@science.horizon.com>
"George Spelvin" <linux@horizon.com> writes:
> (Prompted by the 1.6.2-rc0 announcement.)
>
> Myself, I always thought the obvious way to handle this problem was to
> detach the HEAD.  Is there a reson there's no "detach" option for this?

Let's first think about why pushing into the current branch with the traditional behaviour is bad.

If you are in control of the remote whose current branch was checked out when push was made, there are two cases:

 (1) You do not know what you are doing.  The first time you do "git diff
     HEAD", or perhaps "git status", you suddenly see a lot of reverts,
     sctach your head and cry for help;
     If you set 'detach' option, this clueless user is not helped; he will
     happily keep working and would make tons of commits on detached HEAD,
     and next time he switches to another branch, will lose all of them.
     In a sense, this is a lot worse than the current behaviour, because
     you will do a lot more damage than just a single commit that has many
     uninteniontal reverts as what currently happens---which can be sorted
     out.
 (2) You know what you are doing.  You'd say:
	: detach HEAD at the commit before the push updated the branch
	$ git checkout @{1}  
	$ work work work
        $ git commit
     to detach the HEAD, finish the work you were doing in the pushed-into
     repository and then:
	: check out the previous branch (i.e. go back)
	$ git checkout @{-1}
	: merge the last commit, i.e. the work you done on detached HEAD
        $ git merge @{1}
    If you allow 'detach' option, then you saved him from typing "git
    checkout @{1}".  Not a big gain, especially if you compare this with
    increased pain you are causing to people in category (1).

The case where the pushed-into repository is not yours was discussed previously by Jeff King in the second thread below.

Previous discussions.
    http://thread.gmane.org/gmane.comp.version-control.git/35770/focus=36291
    http://thread.gmane.org/gmane.comp.version-control.git/100339/focus=100731
Previous: George SpelvinNext: Johannes Schindelin
Message 2 of 15 in “receive.denyCurrentBranch”
  1. George SpelvinFeb 8, 2009
  2. Junio C HamanoFeb 8, 2009
  3. Johannes SchindelinFeb 8, 2009
  4. Jay SoffianFeb 8, 2009
  5. Johannes SchindelinFeb 8, 2009
  6. Jay SoffianFeb 8, 2009
  7. Jay SoffianFeb 8, 2009
  8. Johannes SchindelinFeb 8, 2009
  9. Junio C HamanoFeb 9, 2009
  10. Jay SoffianFeb 9, 2009
  11. Theodore TsoFeb 9, 2009
  12. Johannes SchindelinFeb 9, 2009
  13. Jay SoffianFeb 9, 2009
  14. Jay SoffianFeb 9, 2009
  15. Jakub NarebskiFeb 8, 2009

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.