Working on git repo without cd into directory

How would I run git commands on a repo when I am not cd’d into that directory?
i.e. git branch /repos/myrepo.git

  • Why is git apply of a patch with binary files not creating the binary files?
  • git cvsimport fails: Could not merge master into the current branch
  • Git: Pushing multiple branches using wildcards
  • GIT - branches, what is branch?
  • git diff: Show only diff for files that exist in both commits
  • How to undo commit, put into new branch then do a PR?
  • How to truncate field in git log --pretty
  • .gitattributes not making a difference, trying to skip files when using git difftool
  • How to revert changes after git reset
  • Is it possible to revoke commits?
  • Mac OS X restore files deleted by git rm
  • Git doesn't change line-endings after creating .gitattributes file
  • 3 Solutions collect form web for “Working on git repo without cd into directory”


    Set the path to the repository. This can also be controlled by setting the GIT_DIR environment variable. It can be an absolute path or relative path to current working directory.

    Note that <path> above means the path to the actual git directory (project_dir/.git) not just the project directory (project_dir).

    Starting with git 1.8.5, use the -C option.

    git -C "/Users/michael/Development/Projects/opensource/dvsc-backup" status

    Otherwise, you have to specify --work-dir as well as --git-dir

    git --work-dir="/Users/michael/Development/Projects/opensource/dvsc-backup" --git-dir="/Users/michael/Development/Projects/opensource/dvsc-backup/.git" status

    –work-tree might do better 😉

    Git Baby is a git and github fan, let's start git clone.