Sync git workspace with another folder

Is there a standard way to synchronize a git workspace with another directory. Suppose I have a directory managed by git. This directory is displayed externally, as well as its changes (files changed, added and deleted). Then he returns to my car. How can I easily integrate all these changes back into git.

If I just copied the files, then the new and changed files would be fine, but the information about the deleted files would be lost. Is there a way to easily make git rm for files that were deleted when the directory was outside of git?

+6
source share
2 answers

You can use the --work-tree git command option:

 cd /path/to/your/local/repo git --work-tree=/path/to/your/other/directory status git --work-tree=/path/to/your/other/directory add -A . git checkout . 

This will detect new, changed and deleted files.
The last command is mentioned in Mike Lippert to synchronize its own local tree with the index updated.

So you are comparing:

  • the contents of " another/directory " (link to the --work-tree option)
  • with the index of your current repo (where you are running git )
+4
source

VonC's answer looks like the first part of what you want.

The --work-tree option is described on the git (1) page manually

However, after running git --work-tree=/path/to/your/other/directory add -A . your index is different from your local (original) directory. To make the local directory match the index (containing all the changes from the offline directory), run git checkout . .

 git --work-tree=/path/to/your/other/directory add -A . git checkout . 
+5
source

All Articles