Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

specify directory for git pull (not current directory)

Tags:

git

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?

like image 309
alexus Avatar asked Jun 18 '15 20:06

alexus


People also ask

How do I change directory in git directory?

To change this current working directory, you can use the "cd" command (where "cd" stands for "change directory").

Does git fetch change working directory?

git fetch really only downloads new data from a remote repository - but it doesn't integrate any of this new data into your working files. Fetch is great for getting a fresh view on all the things that happened in a remote repository.


1 Answers

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)

like image 126
Jens Hoffmann Avatar answered Sep 18 '22 20:09

Jens Hoffmann