-- Drupal and Web Development

Notice: this post was last updated 3 years 37 weeks ago so it might be outdated. Please be cautious before implementing any of suggestions herein.

Git: specifying a directory without being in it

In case you don't want to cd into a directory, you can still target it with git. See also Here is an example:

mkdir test
cd test
git init
Initialized empty Git repository in /path/to/test/.git/
touch test.txt
git add .
git commit -am 'initial'
[master (root-commit) d0505e5] initial
0 files changed
create mode 100644 test.txt
cd ..
git --git-dir=/path/to/test/.git --work-tree=/path/to/test log

Interestingly, it works in

Interestingly, it works in the above example, but when I'm trying to log onto a remote machine and try it with git pull, I get

fatal: /usr/libexec/git-core/git-pull cannot be used without a working tree.

To avoid that error I must do:

cd /my/git/repo && git pull origin master

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <h3>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.