Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change directory and run git commands using PHPseclib?

Tags:

git

php

phpseclib

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

like image 706
Ananth Ravi Avatar asked Dec 18 '25 01:12

Ananth Ravi


1 Answers

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
like image 98
VonC Avatar answered Dec 20 '25 18:12

VonC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!