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

Re: disallowing push to currently checked-out branch

From
Julian Phillips <julian@quantumfyre.co.uk>
Date
Feb 16, 2009, 01:30 UTC
Message-ID
<alpine.LNX.2.00.0902160103090.7597@reaper.quantumfyre.co.uk>
In-Reply-To
<alpine.DEB.1.10.0902151738450.14911@asgard.lang.hm>
On Sun, 15 Feb 2009, david@lang.hm wrote:
> as I think about this more I'm puzzled as to why this is an issue.

I think that you have a slightly misunderstanding of what fetch is usually configured to do.

Show 9 quoted lines
> I see mentions of it messing up the index and causing users to loose data, 
> but how is it different to push into a repository that has a workdir (with or 
> without dirty state in the workdir or in the index) and doing a fetch into 
> that repository.
>
> in both cases the new commits are added to the repository and the commit 
> pointed to by the branch changes, but if you do the fetch your HEAD and the 
> contents of the workdir and index aren't touched, why should a push do 
> something different?

This isn't the case. A fetch will only update the refs that refer to the state of the remote repository. It will not update any of your local refs (unless you have a mirror setup - in which case a fetch is just as bad as a push).

Say we have two repositories, and local is cloned from remote:
remote# git branch
* master
   foo
local# git branch   #what branches do we have to work on?
* master
   foo
local# git branch -r  #what branches do our remotes have?
   remote/master
   remote/foo

If we have updates on the master branch at remote, then "git fetch remote" on local will update "remote/master", but will not affect "master" - the currently checked out branch. To update "master" we then have to either merge "remote/master" (pull) or rebase "master" onto the new head of "remote/master" (pull --rebase).

However, if we have updates on the master branch at local, then "git push remote master" will update "master" on the remote repository - the checked out branch. At which point the user has to know what they are doing, or risk confusion and lost work, as any commit made on the remote branch will not take account of the changes made by the pushed commits unless care is taken to update the wordir first (and it doesn't make any difference if you didn't have dirty state before the push).

> I believe that if you fetch into a repository and someone else fetches from 
> you, they will get the content that's newer that what's in your dirty 
> workdir/index (I haven't tried it, but my understanding of the git internals 
> lead me to expect this to be the behavior)

Unless they are also pulling your remote tracking branches (which is not the default behaviour, and is a rather odd thing to do), then your fetch will not change what they get from you as they only get your local branches.

> a pull would try to update the index, HEAD, and workdir, but I've seen many 
> discussions about how push and pull are not symetrical, but push and fetch 
> are (along with the moaning about bad names for the commands and the 
> historical explination of how they got that way)

They are symetrical in operation, but not in destination. Basically, the assumption is that when fetching the user is on that machine and will incorporate the updates themselves either using pull, or in a more manual way. With push, the assumption is that there is no user on the remote machine only a lonely old server process, and that the changes should be immediately made available to anyone accessing the repository.

Show 17 quoted lines
> If there is some reason for the normal push to try and update the HEAD, 
> index, and workdir. instead of refusing the push, how about having it put the 
> commits in the repository and then fail to change the HEAD, index, and 
> workdir if any of them contain changes? (along with a warning that it's doing 
> so).
>
> this should be safe to do because it will only flag on the particular 
> combination of events that will cause data loss rather than the broader 
> prohibition of "don't push if there is a workdir" that affects legitimate 
> uses as well
>
> David Lang
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
-- 
Julian

  ---
Q: Does Bill Gates use public domain software?
A: Yes, as all of the public has become Bill Gates' domain.
Previous: david@lang.hmNext: Jeff King
Message 9 of 91 in “[RFC - draft] List of proposed future changes that are backward incompatible”
  1. Junio C HamanoFeb 15, 2009
  2. Junio C HamanoFeb 15, 2009
  3. Jakub NarebskiFeb 15, 2009
  4. Junio C HamanoFeb 15, 2009
  5. Heikki OrsilaFeb 15, 2009
  6. disallowing push to currently checked-out branchJeff King, Feb 16, 2009
  7. david@lang.hmFeb 16, 2009
  8. david@lang.hmFeb 16, 2009
  9. Julian PhillipsFeb 16, 2009
  10. Jeff KingFeb 16, 2009
  11. Daniel BarkalowFeb 16, 2009
  12. Junio C HamanoFeb 16, 2009
  13. Sergio CallegariFeb 16, 2009
  14. Jeff KingFeb 16, 2009
  15. Sergio CallegariFeb 16, 2009
  16. Matthieu MoyFeb 16, 2009
  17. Johannes SchindelinFeb 16, 2009
  18. Jay SoffianFeb 16, 2009
  19. Johannes SchindelinFeb 16, 2009
  20. Jay SoffianFeb 16, 2009
  21. Johannes SchindelinFeb 16, 2009
  22. Jay SoffianFeb 16, 2009
  23. Jeff KingFeb 16, 2009
  24. Jay SoffianFeb 17, 2009
  25. PUSH_HEAD, was Re: disallowing push to currently checked-out branchJohannes Schindelin, Feb 17, 2009
  26. Jay SoffianFeb 17, 2009
  27. Jeff KingFeb 17, 2009
  28. Junio C HamanoFeb 17, 2009
  29. Jay SoffianFeb 17, 2009
  30. Johannes SchindelinFeb 17, 2009
  31. Sergio CallegariFeb 16, 2009
  32. Johannes SchindelinFeb 16, 2009
  33. Jay SoffianFeb 16, 2009
  34. Sergio CallegariFeb 17, 2009
  35. Johannes SchindelinFeb 17, 2009
  36. Sergio CallegariFeb 17, 2009
  37. Johannes SchindelinFeb 17, 2009
  38. Junio C HamanoFeb 17, 2009
  39. Junio C HamanoFeb 17, 2009
  40. Junio C HamanoFeb 16, 2009
  41. Jeff KingFeb 16, 2009
  42. Junio C HamanoFeb 16, 2009
  43. Jeff KingFeb 17, 2009
  44. Junio C HamanoFeb 17, 2009
  45. Jeff KingFeb 17, 2009
  46. Jeff KingFeb 16, 2009
  47. david@lang.hmFeb 16, 2009
  48. Jeff KingFeb 16, 2009
  49. david@lang.hmFeb 16, 2009
  50. Jeff KingFeb 16, 2009
  51. david@lang.hmFeb 16, 2009
  52. Jeff KingFeb 16, 2009
  53. Johannes SchindelinFeb 16, 2009
  54. dashed commands, was Re: disallowing push to currently checked-out branchJohannes Schindelin, Feb 16, 2009
  55. david@lang.hmFeb 15, 2009
  56. Johannes SchindelinFeb 15, 2009
  57. Junio C HamanoFeb 15, 2009
  58. david@lang.hmFeb 16, 2009
  59. Johannes SchindelinFeb 15, 2009
  60. david@lang.hmFeb 16, 2009
  61. Junio C HamanoFeb 16, 2009
  62. Johannes SchindelinFeb 16, 2009
  63. david@lang.hmFeb 16, 2009
  64. Sverre RabbelierFeb 16, 2009
  65. disallowing push to currently checked-out branchJeff King, Feb 16, 2009
  66. Sergio CallegariFeb 16, 2009
  67. Jakub NarebskiFeb 15, 2009
  68. Johannes SchindelinFeb 15, 2009
  69. Jakub NarebskiFeb 15, 2009
  70. david@lang.hmFeb 16, 2009
  71. send-email sending shallow threads by defaultJeff King, Feb 16, 2009
  72. Pieter de BieFeb 16, 2009
  73. Jeff KingFeb 16, 2009
  74. Brian GernhardtFeb 16, 2009
  75. Wincent ColaiutaFeb 16, 2009
  76. SZEDER GáborFeb 16, 2009
  77. Martin MaresFeb 16, 2009
  78. Andreas EricssonFeb 17, 2009
  79. Martin MaresFeb 17, 2009
  80. Jeff KingFeb 17, 2009
  81. Eric W. BiedermanFeb 20, 2009
  82. Jeff KingFeb 20, 2009
  83. Eric W. BiedermanFeb 20, 2009
  84. Andreas EricssonFeb 17, 2009
  85. Sitaram ChamartyFeb 16, 2009
  86. Björn SteinbrinkFeb 16, 2009
  87. Junio C HamanoFeb 16, 2009
  88. Björn SteinbrinkFeb 16, 2009
  89. [RFC - draft #2] List of proposed future changes that are backward incompatibleJunio C Hamano, Feb 16, 2009
  90. Jeff KingFeb 16, 2009
  91. Jakub NarebskiFeb 16, 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.