@@ -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
186186git@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+
188240Common Issues
189241-------------
190242
@@ -241,6 +293,42 @@ How do I know if I want to do a fetch or a pull?::
241293 ignore the upstream changes. A pull consists of a fetch followed
242294 immediately by either a merge or rebase. See linkgit:git-pull[1].
243295
296+ [[proxy]]
297+ Can I use a proxy with Git?::
298+ Yes, Git supports the use of proxies. Git honors the standard `http_proxy`,
299+ `https_proxy`, and `no_proxy` environment variables commonly used on Unix, and
300+ it also can be configured with `http.proxy` and similar options for HTTPS (see
301+ linkgit:git-config[1]). The `http.proxy` and related options can be
302+ customized on a per-URL pattern basis. In addition, Git can in theory
303+ function normally with transparent proxies that exist on the network.
304+ +
305+ For SSH, Git can support a proxy using OpenSSH's `ProxyCommand`. Commonly used
306+ tools include `netcat` and `socat`. However, they must be configured not to
307+ exit when seeing EOF on standard input, which usually means that `netcat` will
308+ require `-q` and `socat` will require a timeout with something like `-t 10`.
309+ This is required because the way the Git SSH server knows that no more requests
310+ will be made is an EOF on standard input, but when that happens, the server may
311+ not have yet processed the final request, so dropping the connection at that
312+ point would interrupt that request.
313+ +
314+ An example configuration entry in `~/.ssh/config` with an HTTP proxy might look
315+ like this:
316+ +
317+ ----
318+ Host git.example.org
319+ User git
320+ ProxyCommand socat -t 10 - PROXY:proxy.example.org:%h:%p,proxyport=8080
321+ ----
322+ +
323+ Note that in all cases, for Git to work properly, the proxy must be completely
324+ transparent. The proxy cannot modify, tamper with, or buffer the connection in
325+ any way, or Git will almost certainly fail to work. Note that many proxies,
326+ including many TLS middleboxes, Windows antivirus and firewall programs other
327+ than Windows Defender and Windows Firewall, and filtering proxies fail to meet
328+ this standard, and as a result end up breaking Git. Because of the many
329+ reports of problems and their poor security history, we recommend against the
330+ use of these classes of software and devices.
331+
244332Merging and Rebasing
245333--------------------
246334
@@ -357,8 +445,9 @@ I'm on Windows and git diff shows my files as having a `^M` at the end.::
357445+
358446You can store the files in the repository with Unix line endings and convert
359447them automatically to your platform's line endings. To do that, set the
360- configuration option `core.eol` to `native` and see the following entry for
361- information about how to configure files as text or binary.
448+ configuration option `core.eol` to `native` and see
449+ <<recommended-storage-settings,the question on recommended storage settings>>
450+ for information about how to configure files as text or binary.
362451+
363452You can also control this behavior with the `core.whitespace` setting if you
364453don't wish to remove the carriage returns from your line endings.
@@ -420,14 +509,26 @@ references, URLs, and hashes stored in the repository.
420509+
421510We also recommend setting a linkgit:gitattributes[5] file to explicitly mark
422511which files are text and which are binary. If you want Git to guess, you can
423- set the attribute `text=auto`. For example, the following might be appropriate
424- in some projects:
512+ set the attribute `text=auto`.
513+ +
514+ With text files, Git will generally ensure that LF endings are used in the
515+ repository. The `core.autocrlf` and `core.eol` configuration variables specify
516+ what line-ending convention is followed when any text file is checked out. You
517+ can also use the `eol` attribute (e.g., `eol=crlf`) to override which files get
518+ what line-ending treatment.
519+ +
520+ For example, generally shell files must have LF endings and batch files must
521+ have CRLF endings, so the following might be appropriate in some projects:
425522+
426523----
427524# By default, guess.
428525* text=auto
429526# Mark all C files as text.
430527*.c text
528+ # Ensure all shell files have LF endings and all batch files have CRLF
529+ # endings in the working tree and both have LF in the repo.
530+ *.sh text eol=lf
531+ *.bat text eol=crlf
431532# Mark all JPEG files as binary.
432533*.jpg binary
433534----
0 commit comments