3

I'm trying to use PHPseclib to SSH and run commands on the remote server. I want to change directory and commands like git pull or clone. Is there a way to do this? I know that "cd" doesn't work well with exec. So any alternatives to this? Thanks

Ananth Ravi
  • 717
  • 2
  • 7
  • 13

1 Answers1

2

You don't need to change folder, only to specify it to your git command.

git --git-dir=/path/to/repo/.git --work-tree=/path/to/repo remote add xxx
git --git-dir=/path/to/repo/.git --work-tree=/path/to/repo pull

Since git 1;8.5 (if your server hasd a recent enough git version installed), you even can use the short version (detailed here)

git -C /path/to/repo remote add xxx
git -C /path/to/repo pull
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Am trying to use the git submodule update command which apparently doesn't seem to work with --git-dir. Any other alternatives? Thanks! – Ananth Ravi Mar 08 '14 at 20:42
  • @AnanthakrishnanRavi then the `-C` option should work. You need to be at the root folder of the parent repo (the one declaring the submodules, and including the submodule folders) – VonC Mar 08 '14 at 20:47