5

I'd like to do update my existing checkout from git, but without being inside of that directory:

-sh-3.2$ pwd
/var/lib/gitolite
-sh-3.2$ git clone repositories/visits.git/
Cloning into 'visits'...
done.
-sh-3.2$ cd visits/
-sh-3.2$ git remote -v
origin  /var/lib/gitolite/repositories/visits.git/ (fetch)
origin  /var/lib/gitolite/repositories/visits.git/ (push)
-sh-3.2$ cd
-sh-3.2$ git --git-dir=/var/lib/gitolite/repositories/visits.git/ --work-tree=/var/lib/gitolite/visits/ pull 
fatal: No remote repository specified.  Please, specify either a URL or a
remote name from which new revisions should be fetched.
-sh-3.2$ cd visits/
-sh-3.2$ git pull
Already up-to-date.
-sh-3.2$ git --version
git version 1.8.2.1
-sh-3.2$ 

I don't really understand git-dir and work-tree, can someone explain what am I doing wrong?

alexus
  • 7,256
  • 12
  • 44
  • 66

1 Answers1

8

git-dir should point to the .git folder of your local copy (yours points to the remote repository you cloned from):

Example:

~/tmp> git clone repositories/my-project.git/
Cloning into 'my-project'...
done.
~/tmp> git --git-dir=/Users/jhoffmann/tmp/my-project/.git \
> --work-tree=/Users/jhoffmann/tmp/my-project/ pull
Already up-to-date.

Git version 1.8.5 introduces -C which simplifies this to:

~/tmp> git -C /Users/jhoffmann/tmp/my-project/ pull
Already up-to-date.

(taken from this answer)

Community
  • 1
  • 1
Jens Hoffmann
  • 6,699
  • 2
  • 25
  • 31