Git pull and specify directory?

i would like to run a git pull and specify the directory. some say using –git-dir and –work-tree should work but such as

git --git-dir=/var/www/.git --work-tree=/var/www pull

put this returns a “cannot be used without a working tree”. The only time i can get this to work is if i use “.”, “..” or any directory above the current directory

  • ssh not working, muxserver_listen bind(): No such file or directory
  • How is a merge-base done in JGit?
  • How to shallow clone a specific commit with depth 1?
  • Prevent merging a file from master with Git
  • How to make “git branch” respect the “core.ignorecase” flag on Linux?
  • Jenkins is throwing a hudson.util.IOException2 on a Windows 2008 Server
  • this post suggests maybe a bug?
    git pull while not in a git directory

    in the end i need to run a sudo git pull in a single line. i welcome any work arounds. thanks

  • How do you do merges using Git, Eclipse and Egit
  • Setting up GIT for Symfony2 project: why add web/bundles folder to gitignore
  • How to squash all git commits into one?
  • Git push results in fatal: protocol error: bad line length character: This
  • git checkout-index: unable to create file (File name too long)
  • cannot push into git repository
  • 4 Solutions collect form web for “Git pull and specify directory?”

    Use sudo and give the command as an argument to sh?

    Something like:

    sudo sh -c 'cd /dir && git pull'

    In the two years since this question was answered, Git 1.8 came out which supports calling git in other directories using the -C flag:

    git -C /var/www pull

    You are using --work-dir, which is not the right paramter. It is --work-tree and should work for what you want. Or you can just do cd /var/www && git pull if you wanted the pull to be in a single command / line.

    On Windows in MINGW64:

    git -C "C:\Trunk190117\crewcontrol-source" pull


    git -C /c/Trunk190117/crewcontrol-source pull
    Git Baby is a git and github fan, let's start git clone.