1

I am not able to pull a file remotely from git server through php. I wrote the following BAT code and am trying to execute it via php. the batch file git1.bat is a follows:

cd C:\repos\rep2 && git pull origin master 2>&1

the php code:

<?php
echo shell_exec("C:\\xampp\htdocs\AS-otg\\git1.bat");
?>

the output I get:

enter image description here

However, I get the required result when I do the same directly from cmd. enter image description here

I tried some other git commands like log etc. which work just fine. I need to do this via php only... please help.

1 Answer 1

1

log is a local command that does not need to talk with a remote host. pull does a fetch first. It seems you are running the PHP script under another user than when you run the script manually. If you run it manually you authenticate to the remote server with your SSH key and when the PHP script runs the script, the effective user does not have that SSH key to authenticate with.

Btw. you should keep in mind that a pull is not suited for being done non-interactively. When doing a pull you can easily get conflicts if the incoming changes are not fast-forward.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.