Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


git-dir and work-tree #151

poymode opened this Issue · 2 comments

2 participants


Not a bug or feature but a question for the code.

First of all, here's my code:

require 'grit'

repo = Grit::Repo.init('/tmp/repo')

# or i could say

In a non-grit way, this could have been (in native git)

mkdir /tmp/repo
cd /tmp/repo
git init
git remote add origin
git fetch --all
git reset --hard origin/master

Reading grit code, I discovered that running a command, sends your to a method_missing and calls a method call native.

So what happens is that every native command that is going to be executed in grit, the --git-dir option is always prefixed to the command. so example, a:

repo.git.reset({:hard=>true}, 'origin/master')

would be translated to:

git --git-dir=/tmp/repo/.git reset --hard origin/master

After this, when typing git log on my repo, it shows my current HEAD commit but all my files under git status are marked as modified and deleted.

I tried again on the command line and set the --work-tree(--git-dir without the .git) option and it works as intended.

So I am confused on why grit only prepends the --git-dir option without --work-tree.

Also, if i manually specify a work_tree option under the first argument of native, it will treat work-tree as an option to the command and not an option to the git binary.


I'm using this workaround:

mypath = '/xx/xx'
repo =
repo.git.reset({:env => {'GIT_WORK_TREE' => mypath}, :hard => true}, commit_id)

@nand2 Yeah this could work. Thanks!

@poymode poymode closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.