How to push git from php using exec()

Asked
Active3 hr before
Viewed126 times

7 Answers

using
90%

I am running the webserver from localhost. When I run php -r "$ret = exec('abhishek3.bat'); echo $ret;" from cmd it executes the batch file successfully. If I run it from webpage it doesn't performs the push.. – Snehasish Oct 5 '14 at 12:48 , git init runs successfully.. git commit runs successfully... git push doesn't runs when run through php web page (It runs when executed from PHP CLI..) What can be the cause of it ? – Snehasish Oct 6 '14 at 8:04 , Firewall was already disabled. Also I set the execution policy to unrestricted but git push heroku master didn't worked. – Snehasish Oct 9 '14 at 19:06 ,The above snippet runs successfully when run from cmd but when run from php through exec() didn't worked. Download hstart (Hidden Start Binary)

Here is my push.bat file

echo "Hello world!"
cd abhishek3 /
   call git add.
call git commit - m "sadf"
call heroku accounts: set abhishek84
call git push heroku master
load more v
88%

exec('git push origin ’ . $branch);,How can I enter that username and password via the script?,I’m writing a script to automatically push code to a git server. I’m using php and running the script via the command line. After asking the user to enter the branch and commit message, the following code runs: exec(‘git config user.name "’ . $userName . ‘"’); exec(‘git config user.email "’ . $userEmail . ‘"’);,I’ve since found and tried proc_open(), but I still can’t get it to actually send the input to the git push command.

When I wrote my backup program, I was using a personal access token which should bypass the need to authenticate because this personal access token says “Hey, I am who I say I am”. But without the 1 line that uses a username and password, it’ll actually return this message.

stdClass Object
   (
      [message] => Requires authentication[documentation_url] => https: //developer.github.com/v3/repos/#create
   )
load more v
72%

But if I try doing that via the PHP shell_exec() backticks ` ` nothing happens. I even tried adding pauses.,Anyone know what I'm doing wrong here? Should I be placing these calls in a bash script and then calling it via a PHP template?, @Attie the PHP script is working correctly in all other ways, even simple git calls like git status work perfectly. The problem is when it trys to call git commit -m "from server", I simply don't see any output to determine if it's even working at all. – Vince Oct 4 '18 at 15:40 , Villain uses hero to kill people by hitting them with him

If one of these changes on the sever happens my scripts tell me about it no problem.

git status

# On branch master
# Changes to be committed:
   #(use "git reset HEAD ..."
      to unstage)
#
# new file: somefolder / somenewfile.whatever
#
load more v
65%

$git->command() will create a new command, *->option() will add an option to the command and *->execute() will finally execute the command.,The naming of commands and options follow the git naming. If you search for documentation of a specific command or option, just look into the git documentation. You will find the command/option there.,The API use command builders, that allow you to build a command and execute it one time.,The clone command is named cloneRepository() because clone is a reserved word in PHP.

$git - > command() - > option() - > execute();
load more v
75%

I've tried using an output buffer described here to no avail. I'm sure theres something on SO that can answer this, but haven't been able to find it after much digging..,git sends its output to STDERR not STDOUT so you will need to redirect that with something like this:,The first line of my script is Running it I get Even if I put sudo before the mount command it does not find sudo neither. Thank you for your help,I would like to have the output of the push inside $shell_output, but its not happening (The output just shows up on terminal). I think because git is an external program and therefore creates a new output stream?

I have a line where I do this:

exec("git push {$remote} {$branch}:{$branch}", $shell_output, $status);
40%

This hook is invoked by git-commit[1] right after preparing the default log message, and before the editor is started.,This hook is invoked by git-p4 submit.,This hook is invoked by git-commit[1]. It takes no parameters, and is invoked after a commit is made.,This hook is invoked by git-am[1]. It takes no parameter, and is invoked after the patch is applied and a commit is made.

<local ref> SP <local object name> SP <remote ref> SP <remote object name> LF
load more v
22%

Two testing scenarios are covered: using the Docker executor and using the Shell executor. ,The majority of the PHP projects use Composer for managing their PHP packages. To execute Composer before running your tests, add the following to your .gitlab-ci.yml: , Test PHP projects using the Docker executor Test against different PHP versions in Docker builds Custom PHP configuration in Docker builds ,You have to install it on your build machine under the gitlab-runner user following the upstream installation guide.

image: php: 5.6
load more v

Other "using-undefined" queries related to "How to push git from php using exec()"