Run `git commit` from another directory
You can also use the environment variables $GIT_DIR
and $GIT_WORK_TREE
to the same effect as --git-dir
and --work-tree
These are the steps to commit a file when you are in another directory:
git --git-dir=/path/to/my/directory/.git/ --work-tree=/path/to/my/directory/ add myFile
git --git-dir=/path/to/my/directory/.git/ --work-tree=/path/to/my/directory/ commit -m 'something'
You can use git -C <path>
.
From https://git-scm.com/docs/git/2.4.4
git -C <path>: Run as if git was started in <path> instead of the current working directory.