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

  • Macintosh Git SSH key setup
  • Are merges in Git different than in Mercurial?
  • Git: interactive rebase lists incorrect (too many) commits
  • Migrating virtualenv and Github between computers
  • How to create git-compatible patch from svn revision, that contains binary file changes?
  • HTTPS credentials: obfuscate console or pop-up window input
  • 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

  • Git deleted untracked files on pull
  • Pushing local repo to remote does not push submodule files using GIT
  • How can I setup hudson (or jenkins) build from release/hotfix branches using the git-flow branching model?
  • Git: a tool to manage and to structure Projects?
  • Git submodule pull overwrite/discard any local changes
  • Git: Preventing Commit During a Rebase
  • 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.