4

In Git you can clone a given directory to given directory:

git clone ssh://gitolite@dev.bipper.com:3687/com/bipper/kids/portal <dir>

Cause of some intricate issues with "cd" command when I run one of our build scripts I would like to take git pull something like this:

git pull <dir-to-the-git-folder>

Ergo not having to be in the git folder when executing the pull (or fetch/merge) when doing so, is it possible to achieve somehow (my above example doesn't work)

greg0ire
  • 22,714
  • 16
  • 72
  • 101
Thomas Vervik
  • 4,325
  • 9
  • 36
  • 64

3 Answers3

4

I think you should have a look at the git-dir and perhaps also work-tree options. You can also use the GIT_DIR / GIT_WORK_TREE variables if you prefer to.

See the manual :

--git-dir=<path> Set the path to the repository. This can also be controlled by setting the GIT_DIR environment variable. It can be an absolute path or relative path to current working directory.

-work-tree=<path> Set the path to the working tree. It can be an absolute path or a path relative to the current working directory. This can also be controlled by setting the GIT_WORK_TREE environment variable and the core.worktree configuration variable (see core.worktree in git-config(1) for a more detailed discussion).

greg0ire
  • 22,714
  • 16
  • 72
  • 101
  • hmm, btw, trying to this on our linux server git --git-dir=/tmp/deployment_1347960691855 --work-tree=/tmp/deployment_1347960691855 pull But get WARN:fatal: Not a git repository: '/tmp/deployment_1347960691855' But it is a Git repo – Thomas Vervik Sep 18 '12 at 09:32
  • Also tried locally on my Windows machine with an other Git project I have: C:\>git --git-dir=C:\projectsGit\bsafe-server --work-tree=C:\projectsGit\bsafe-server pull fatal: Not a git repository: 'C:\projectsGit\bsafe-server' – Thomas Vervik Sep 18 '12 at 09:33
  • 1
    Maybe you should try `C:\projectsGit\basfe-server\.git` for the git-dir option... see this question : http://stackoverflow.com/questions/1386291/git-git-dir-not-working-as-expected Not what the manual says, though... – greg0ire Sep 18 '12 at 10:05
1

Try

GIT_DIR=<dir-to-the-git-folder>/.git GIT_WORK_TREE=<dir-to-the-git-folder> git pull

You can also specify these options using --git-dir and --work-tree respectively.

From man git:

   --git-dir=<path>
       Set the path to the repository. This can also be controlled by setting the GIT_DIR environment
       variable. It can be an absolute path or relative path to current working directory.

   --work-tree=<path>
       Set the path to the working tree. It can be an absolute path or a path relative to the current
       working directory. This can also be controlled by setting the GIT_WORK_TREE environment variable
       and the core.worktree configuration variable (see core.worktree in git-config(1) for a more
       detailed discussion).
nneonneo
  • 171,345
  • 36
  • 312
  • 383
1

As of git 1.8.5 you can use the -C option to change the dir context.

sudo -u www-data -H git -C /var/www/ status

-H will set the home-dir for your command. It is optional, but usefull when you want to avoid the following errors:

warning: unable to access '/root/.config/git/attributes': Permission denied
or
warning: unable to access '/home/user/.config/git/attributes': Permission denied
Aley
  • 8,540
  • 7
  • 43
  • 56