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

Re: [PATCH v2 3/3] gitfaq: add entry about syncing working trees

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Nov 8, 2021, 00:12 UTC
Message-ID
<CAPig+cRtOpaPd_HCQAW=33-vxhP4Knijo3g0dUA9HVb4_=JH4w@mail.gmail.com>
In-Reply-To
<20211107225525.431138-4-sandals@crustytoothpaste.net>

On Sun, Nov 7, 2021 at 5:55 PM brian m. carlson <sandals@crustytoothpaste.net> wrote:

Show 17 quoted lines
> Users very commonly want to sync their working tree with uncommitted
> changes across machines, often to carry across in-progress work or
> stashes.  Despite this not being a recommended approach, users want to
> do it and are not dissuaded by suggestions not to, so let's recommend a
> sensible technique.
> [...]
> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
> ---
> diff --git a/Documentation/gitfaq.txt b/Documentation/gitfaq.txt
> @@ -185,6 +185,49 @@ Then, you can adjust your push URL to use `git@example_author` or
> +[[sync-working-tree]]
> +How do I sync a working tree across systems?::
> +       First, decide whether you want to do this at all.  Git usually works better
> +       when you push or pull your work using the typical `git push` and `git fetch`
> +       commands and isn't designed to share a working tree across systems.  This is
> +       potentially risky and in some cases can cause repository corruption or data
> +       loss.

The phrase "usually works better" makes this statement feel weak, thus it may not convey the potential severity of the issue. I wonder if rewording it something like this would make the statement more forceful:

    Git works best when you `git push` and `git pull` your work
    between machines; it is not designed to share a working tree
    across systems. [...]
Show 12 quoted lines
> +Usually, doing so will cause `git status` to need to re-read every file in the
> +working tree.  Additionally, Git's security model does not permit sharing a
> +working tree across untrusted users, so it is only safe to sync a working tree
> +if it will only be used by a single user across all machines.
> ++
> +It is important not to use a cloud syncing service to sync any portion of a Git
> +repository, since this can cause corruption, such as missing objects, changed
> +or added files, broken refs, and a wide variety of other corruption.  These
> +services tend to sync file by file and don't understand the structure of a Git
> +repository.  This is especially bad if they sync the repository in the middle of
> +it being updated, since that is very likely to cause incomplete or partial
> +updates and therefore data loss.

Taking into consideration that people who are experiencing such corruption will likely include the name of the syncing service in their search query, would it make sense to mention some well-known services here in order to make it more likely that people will actually find this entry? Something like this, perhaps:

    It is important not to use a cloud syncing service (such as DropBox,
    FooBar, CowMoo, BuzzingBee, etc.) to sync any portion of a Git
    repository...
Show 10 quoted lines
> +Therefore, it's better to push your work to either the other system or a central
> +server using the normal push and pull mechanism.  However, this doesn't always
> +preserve important data, like stashes, so some people prefer to share a working
> +tree across systems.
> ++
> +If you do this, the recommended approach is to use `rsync -a --delete-after`
> +(ideally with an encrypted connection such as with `ssh`) on the root of
> +repository.  You should ensure several things when you do this:
> ++
> +* There are no additional worktrees enabled for your repository.

I don't fully understand this restriction. Can you explain it (at least here in the email discussion)?

> +* You are not using a separate Git directory outside of your repository root.
Same question about this restriction.
Show 10 quoted lines
> +* You are comfortable with the destination directory being an exact copy of the
> +       source directory, _deleting any data that is already there_.
> +* The repository is in a quiescent state for the duration of the transfer (that
> +       is, no operations of any sort are taking place on it, including background
> +       operations like `git gc` and operations invoked by your editor).
> ++
> +Be aware that even with these recommendations, syncing in this way has some risk
> +since it bypasses Git's normal integrity checking for repositories, so having
> +backups is advised.  You may also with to do a `git fsck` to verify the
> +integrity of your data on the destination system after syncing.
s/with/wish/

In fact, as with "usually" above, "wish" may be too weak. Perhaps say instead that it is "recommended" that you use `git fsck` to verify the integrity.

Previous: brian m. carlsonNext: Junio C Hamano
Message 8 of 19 in “Additional FAQ entries”
  1. 0/3 Additional FAQ entriesbrian m. carlson, Nov 7, 2021
  2. 1/3 gitfaq: add documentation on proxiesbrian m. carlson, Nov 7, 2021
  3. Eric SunshineNov 7, 2021
  4. brian m. carlsonNov 8, 2021
  5. Junio C HamanoNov 8, 2021
  6. Johannes SchindelinJan 4, 2022
  7. 3/3 gitfaq: add entry about syncing working treesbrian m. carlson, Nov 7, 2021
  8. Eric SunshineNov 8, 2021
  9. Junio C HamanoNov 8, 2021
  10. Junio C HamanoNov 9, 2021
  11. brian m. carlsonNov 14, 2021
  12. 2/3 gitfaq: give advice on using eol attribute in gitattributesbrian m. carlson, Nov 7, 2021
  13. Eric SunshineNov 7, 2021
  14. brian m. carlsonNov 8, 2021
  15. Eric SunshineNov 8, 2021
  16. Johannes SchindelinJan 4, 2022
  17. Johannes SchindelinJan 4, 2022
  18. brian m. carlsonJan 6, 2022
  19. Eric SunshineNov 9, 2021

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.