How do I execute a Git command without being in the repository?

git

Solution

Try:

git --git-dir=/home/repo/.git log

It is important to give the path all the way up to the .git directory of your repository. Otherwise you will get only an error message that says something like:

fatal: Not a git repository

Problem

Is there a way to execute Git commands against a repository without being in that repository? For example something like this: `git /home/repo log`? Please do not tell me to `cd` to it. I'm doing this via an `exec` call.

Original source

Related problems