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

Re: Newbie grief

From
SRSeth Robertson <in-gitvger@baka.org>
Date
Apr 30, 2012, 23:31 UTC
Message-ID
<201204302331.q3UNVo7o032303@no.baka.org>
In-Reply-To
<4F9F128C.5020304@palm.com>
In message <4F9F128C.5020304@palm.com>, Rich Pixley writes:
    Hey.  I'm a newbie struggling to understand git.
    I'm trying to do what seems like a simple thing in darcs, monotone,
    mecurial, gnu arch, etc, but seems nearly impossible in git.  There's a
    central repository, a long ways away on the other side of the internet.
    So I want a local repository cache.  I'm going to be working on a number
    of different features and different machines all simultaneously so I
    really don't want them all to be pulling from the central repository.

Are you working with anyone else locally? If not, then what you are probably really trying to do is save time on fetches, so that the latest changes are more likely to be nearby than far away.

What I would do is set up a bare backup/--mirror repository of the upstream locally and have it automatically kept up to date with cron or something like that. Then you can have your pull URL point to this mirror and the push URL point to the real upstream. This will work as long as the real upstream and the local mirror are not out of date (if they are, you will be forbidden to push without either pulling from the real upstream or wait for the next cron fetch and pull from your local mirror).

This works, but requires that you separate your fetch and push URLs. Another option is to use git "alternates" to have your local repository also look at the automatically updated repository so that you would only fetch over-the-network-changes since the last automatic fetch (which, unless you had the cache have an alternate for the primary repository, would mean that the changes would be transferred twice).

Alternates can be problematic if you start moving repositories around or delete them or whatever since the repository with the dangling alternate will then be bad (until the objects reappear one way or another), so perhaps you just want a cron job to `git fetch` or `git remote update -p` in your local repository every so often. Then you can just `git merge` or `git rebase` to get the latest changes instead of `git pull [--rebase]`. This is really the simplest solution. No extra repositories, no configuration changes, just straightforward git operations. The only trick would be race conditions between you (as a human) reviewing the latest changes and then typing the command to merge/rebase them into your local branch and the cron job updating the remote—seeing what happened afterwords would of course work. I would probably try this first and only start using the others if this became problematic for some reason.

None of these cases specifically handles trying to automate pushes, mostly because it cannot always be automatically resolved (and depending on local standards on running test suites before any change is pushed, perhaps should not ever be automatically resolved even for trivial conflicts) if changes appear on the real upstream between your last pull and your next push.

Could it be done? Sure. You can push to your local upstream and then have it push out automatically, but if there are conflicts you will need to deal with them, and I would suggest doing so with a bare repository, essentially by having a static preference for the real-upstream's changes and have the cron job send mail to you telling you to re-pull and re-push if it failed to push out due to the remote having changed (telling you the ref/SHA1 that it failed to push).

Of course, this isn't *that* different from just sticking a `git push` into the background which sends mail/notifies if the push failed for some reason, and again doing so would be much easier than an intermediary repository solution.

    But with git, I can't push unless the cache repository is bare,
    but if the cache repository is bare, then a change to the central
    repository will cause the two to become wedged since neither can
    push or fetch the other.

Not strictly speaking true. By default git will forbid pushes to non-bare repositories (see receive.denyCurrentBranch in man git-config) since without special automation the working directory will get out of date. See http://bare-vs-nonbare.gitrecipes.de/ for more information. However, I cannot think that having to perform integration in this second repository would actually work.

    It seems that git is allergic to the dual head branch solution or
    something, which is surprising and disappointing.

Git tracks your version of master separately from each other remote's master. This is exactly dual/multiple heads. What git *does* forbid (by default) is:

1: Letting you update someone else's checked out (non-bare) repository underneath them

2: Letting you update someone else's repository if they have more recent changes than you do.

Both of these defaults are really good ideas, but you can disable them if you think you know better.

					-Seth Robertson
Previous: Rich PixleyNext: Rich Pixley
Message 2 of 100 in “Newbie grief”
  1. Rich PixleyApr 30, 2012
  2. Seth RobertsonApr 30, 2012
  3. Rich PixleyMay 1, 2012
  4. Junio C HamanoMay 1, 2012
  5. Rich PixleyMay 1, 2012
  6. Sitaram ChamartyMay 1, 2012
  7. Ted Ts'oMay 1, 2012
  8. Sitaram ChamartyMay 1, 2012
  9. Rich PixleyMay 1, 2012
  10. Michael WittenMay 1, 2012
  11. Rich PixleyMay 1, 2012
  12. Jakub NarebskiMay 2, 2012
  13. Randal L. SchwartzMay 1, 2012
  14. Rich PixleyMay 1, 2012
  15. Randal L. SchwartzMay 1, 2012
  16. Junio C HamanoMay 1, 2012
  17. Rich PixleyMay 1, 2012
  18. Randal L. SchwartzMay 1, 2012
  19. Rich PixleyMay 1, 2012
  20. Michael WittenMay 1, 2012
  21. Philip OakleyMay 1, 2012
  22. Hallvard Breien FurusethMay 3, 2012
  23. Rich PixleyMay 3, 2012
  24. Hallvard Breien FurusethMay 3, 2012
  25. Hallvard Breien FurusethMay 3, 2012
  26. Rich PixleyMay 3, 2012
  27. Junio C HamanoMay 3, 2012
  28. Rich PixleyMay 3, 2012
  29. Randal L. SchwartzMay 3, 2012
  30. Junio C HamanoMay 3, 2012
  31. Felipe ContrerasMay 4, 2012
  32. Felipe ContrerasMay 4, 2012
  33. Michael WittenMay 4, 2012
  34. Rich PixleyMay 1, 2012
  35. Randal L. SchwartzMay 1, 2012
  36. Rich PixleyMay 1, 2012
  37. Andreas EricssonMay 1, 2012
  38. PJ WeisbergMay 1, 2012
  39. Rich PixleyMay 3, 2012
  40. Nathan GrayMay 3, 2012
  41. Rich PixleyMay 3, 2012
  42. Randal L. SchwartzMay 3, 2012
  43. Rich PixleyMay 3, 2012
  44. Mark BrownMay 4, 2012
  45. Rich PixleyMay 4, 2012
  46. Jakub NarebskiMay 4, 2012
  47. Mark BrownMay 4, 2012
  48. Hallvard Breien FurusethMay 2, 2012
  49. Michael WittenMay 2, 2012
  50. Hallvard Breien FurusethMay 3, 2012
  51. Randal L. SchwartzMay 3, 2012
  52. Michael WittenMay 3, 2012
  53. Hallvard Breien FurusethMay 3, 2012
  54. Michael WittenMay 3, 2012
  55. Rich PixleyMay 3, 2012
  56. Ted Ts'oMay 3, 2012
  57. Felipe ContrerasMay 1, 2012
  58. Rich PixleyMay 3, 2012
  59. Rich PixleyMay 3, 2012
  60. Andreas EricssonMay 4, 2012
  61. Stephen BashMay 4, 2012
  62. Mark BrownMay 4, 2012
  63. Felipe ContrerasMay 4, 2012
  64. Rich PixleyMay 1, 2012
  65. Jan KrügerApr 30, 2012
  66. Rich PixleyMay 1, 2012
  67. Philippe VaucherMay 2, 2012
  68. Seth RobertsonMay 1, 2012
  69. Rich PixleyMay 1, 2012
  70. Michael WittenMay 1, 2012
  71. Junio C HamanoMay 1, 2012
  72. Michael WittenMay 1, 2012
  73. Rich PixleyMay 1, 2012
  74. Rich PixleyMay 1, 2012
  75. Rich PixleyMay 3, 2012
  76. Ronan KeryellMay 3, 2012
  77. Junio C HamanoMay 3, 2012
  78. Ronan KeryellMay 3, 2012
  79. Rich PixleyMay 3, 2012
  80. Rich PixleyMay 3, 2012
  81. Illia BobyrMay 4, 2012
  82. Nathan GrayMay 4, 2012
  83. Michael WittenMay 4, 2012
  84. Junio C HamanoMay 4, 2012
  85. Carlos Martín NietoMay 4, 2012
  86. Junio C HamanoMay 4, 2012
  87. Junio C HamanoMay 4, 2012
  88. Nathan GrayMay 4, 2012
  89. Illia BobyrMay 4, 2012
  90. Rich PixleyMay 4, 2012
  91. Rich PixleyMay 4, 2012
  92. Michael WittenMay 4, 2012
  93. Andrew SayersMay 4, 2012
  94. Jérôme BenoitMay 4, 2012
  95. Felipe ContrerasMay 4, 2012
  96. Junio C HamanoMay 4, 2012
  97. Felipe ContrerasMay 4, 2012
  98. Rich PixleyMay 4, 2012
  99. Felipe ContrerasMay 4, 2012
  100. Sitaram ChamartyMay 2, 2012

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.