简体   繁体   中英

php exec() - git push origin master not working, but other git commands are working

I used below code :

    echo exec("git add . ");  //this is working  
echo exec("git commit -am 'first commit' "); //also working  
echo exec("git push origin master");  //NOT WORKING, also not showing any error . 

I chowned folder permissions from user to www-data . So, some git commands are working but

GIT PUSH ORIGIN MASTER

is not working from php exec . What is the solution ? Also, please tell me why PUSH in exec NOT showing any error or msg, how can i see those msgs . Also,if possible, please provide me any good links for more advanced use of git commands from php exec .

Update : I also tried this : I added post-commit hook by creating file .git/hooks/post-commit

I added this code to it :

git push origin master

But I didnt get any msg or error after commiting, it just commited but didnt do any push.

Thanks !

I assume the push command will try to push to a remote repository (ie not another folder on your system but a remote server behind SSH/HTTPS).

In this case you are most likely missing a HTTPS client certificate HTTPS or an SSH key. Your webserver (and therefore PHP) most likely runs as a different user and does not have access to the private key. Next to that if the private key needs a password it will not work because the exec command is not an interactive session.

Anyway I heavily recommend you to use some sort of bindings and not calling the binaries. Any direct call will start a new process and this is way more inefficient that calls into a library.

Have you checked which branch your are on? 'git status' will tell you.

I'd also recommend working on a branch and not directly on master.

git branch dev_test

git checkout dev_test

git add .

git commit -a -m "first comment"

git push origin dev_test

git checkout master

git merge dev_test

git push origin master

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM