Skip to content

Commit 02fc44a

Browse files
bk2204gitster
authored andcommitted
gitfaq: document using stash import/export to sync working tree
Git 2.51 learned how to import and export stashes. This is a secure and robust way to transfer working tree states across machines and comes with almost none of the pitfalls of rsync or other tools. Recommend this as an alternative in the FAQ. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 9a2fb14 commit 02fc44a

1 file changed

Lines changed: 29 additions & 12 deletions

File tree

Documentation/gitfaq.adoc

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,30 @@ of refs, such that both sides end up with different commits on a branch that
214214
the other doesn't have. This can result in important objects becoming
215215
unreferenced and possibly pruned by `git gc`, causing data loss.
216216
+
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:
217+
Therefore, it's better to push your work to either the other system or a
218+
central server using the normal push and pull mechanism. In Git 2.51, Git
219+
learned to import and export stashes, so it's possible to synchronize the state
220+
of the working tree by stashing it with `git stash`, then exporting either all
221+
stashes with `git stash export --to-ref refs/heads/stashes` (assuming you want
222+
to export to the `stashes` branch) or selecting stashes by adding their numbers
223+
to the end of that command. It's also possible to include untracked files by
224+
using the `--include-untracked` argument when stashing the data in the first
225+
place, but be careful not to do this if any of these contain sensitive
226+
information.
227+
+
228+
You can then push the `stashes` branch (or whatever branch you've exported to),
229+
fetch them to the local system (such as with `git fetch origin
230+
+stashes:stashes`), and import the stashes on the other system with `git stash
231+
import stashes` (again, changing the name as necessary). Applying the changes
232+
to the working tree can be done with `git stash pop` or `git stash apply`.
233+
This is the approach that is most robust and most likely to avoid unintended
234+
problems.
235+
+
236+
Having said that, there are some cases where people nevertheless prefer to
237+
share a working tree across systems. If you do this, the recommended approach
238+
is to use `rsync -a --delete-after` (ideally with an encrypted connection such
239+
as with `ssh`) on the root of repository. You should ensure several things
240+
when you do this:
225241
+
226242
* If you have additional worktrees or a separate Git directory, they must be
227243
synced at the same time as the main working tree and repository.
@@ -232,10 +248,11 @@ repository. You should ensure several things when you do this:
232248
any sort are taking place on it, including background operations like `git
233249
gc` and operations invoked by your editor).
234250
+
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.
251+
Be aware that even with these recommendations, syncing working trees in this
252+
way has some risk since it bypasses Git's normal integrity checking for
253+
repositories, so having backups is advised. You may also wish to do a `git
254+
fsck` to verify the integrity of your data on the destination system after
255+
syncing.
239256

240257
Common Issues
241258
-------------

0 commit comments

Comments
 (0)