Skip to content

Commit 804ecbc

Browse files
bk2204gitster
authored andcommitted
gitfaq: add entry about syncing working trees
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. The technique that many users are using is their preferred cloud syncing service, which is a bad idea. Users have reported problems where they end up with duplicate files that won't go away (with names like "file.c 2"), broken references, oddly named references that have date stamps appended to them, missing objects, and general corruption and data loss. That's because almost all of these tools sync file by file, which is a great technique if your project is a single word processing document or spreadsheet, but is utterly abysmal for Git repositories because they don't necessarily snapshot the entire repository correctly. They also tend to sync the files immediately instead of when the repository is quiescent, so writing multiple files, as occurs during a commit or a gc, can confuse the tools and lead to corruption. We know that the old standby, rsync, is up to the task, provided that the repository is quiescent, so let's suggest that and dissuade people from using cloud syncing tools. Let's tell people about common things they should be aware of before doing this and that this is still potentially risky. Additionally, let's tell people that Git's security model does not permit sharing working trees across users in case they planned to do that. While we'd still prefer users didn't try to do this, hopefully this will lead them in a safer direction. Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c98f78b commit 804ecbc

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

Documentation/gitfaq.txt

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,58 @@ Then, you can adjust your push URL to use `git@example_author` or
185185
`git@example_committer` instead of `[email protected]` (e.g., `git remote set-url
186186
git@example_author:org1/project1.git`).
187187

188+
Transfers
189+
---------
190+
191+
[[sync-working-tree]]
192+
How do I sync a working tree across systems?::
193+
First, decide whether you want to do this at all. Git works best when you
194+
push or pull your work using the typical `git push` and `git fetch` commands
195+
and isn't designed to share a working tree across systems. This is
196+
potentially risky and in some cases can cause repository corruption or data
197+
loss.
198+
+
199+
Usually, doing so will cause `git status` to need to re-read every file in the
200+
working tree. Additionally, Git's security model does not permit sharing a
201+
working tree across untrusted users, so it is only safe to sync a working tree
202+
if it will only be used by a single user across all machines.
203+
+
204+
It is important not to use a cloud syncing service to sync any portion of a Git
205+
repository, since this can cause corruption, such as missing objects, changed
206+
or added files, broken refs, and a wide variety of other problems. These
207+
services tend to sync file by file on a continuous basis and don't understand
208+
the structure of a Git repository. This is especially bad if they sync the
209+
repository in the middle of it being updated, since that is very likely to
210+
cause incomplete or partial updates and therefore data loss.
211+
+
212+
An example of the kind of corruption that can occur is conflicts over the state
213+
of refs, such that both sides end up with different commits on a branch that
214+
the other doesn't have. This can result in important objects becoming
215+
unreferenced and possibly pruned by `git gc`, causing data loss.
216+
+
217+
Therefore, it's better to push your work to either the other system or a central
218+
server using the normal push and pull mechanism. However, this doesn't always
219+
preserve important data, like stashes, so some people prefer to share a working
220+
tree across systems.
221+
+
222+
If you do this, the recommended approach is to use `rsync -a --delete-after`
223+
(ideally with an encrypted connection such as with `ssh`) on the root of
224+
repository. You should ensure several things when you do this:
225+
+
226+
* If you have additional worktrees or a separate Git directory, they must be
227+
synced at the same time as the main working tree and repository.
228+
* You are comfortable with the destination directory being an exact copy of the
229+
source directory, _deleting any data that is already there_.
230+
* The repository (including all worktrees and the Git directory) is in a
231+
quiescent state for the duration of the transfer (that is, no operations of
232+
any sort are taking place on it, including background operations like `git
233+
gc` and operations invoked by your editor).
234+
+
235+
Be aware that even with these recommendations, syncing in this way has some risk
236+
since it bypasses Git's normal integrity checking for repositories, so having
237+
backups is advised. You may also wish to do a `git fsck` to verify the
238+
integrity of your data on the destination system after syncing.
239+
188240
Common Issues
189241
-------------
190242

0 commit comments

Comments
 (0)