简体   繁体   中英

How can I run git commands via shell script?

I have my main repo on my server and two clones.

One clone is on my local for editing. Another copy is on my server in the public folder to pull the changes and view them live.

The current routine I'm going through is edit local -> log into my server to the public folder and do a git pull to see the updated changes.

I would like to use the git hooks "post-receive" shell script to change into the public folder and do a git pull origin master...I just can't seem to figure out how to do this properly. I tried this using:

cd /home/demo/public_html/example.com/public/ && `git status`

But the return I get is "not a repository"

However, if I run cd /home/demo/public_html/example.com/public/ && ls

I WILL get the contents of the public folder (so I'm moving into the right place) Thanks in advanced!

UPDATE:

Should have mentioned I was trying this with and without ticks

首先,在执行git pull或git status测试之前,尝试取消设置GIT_DIR env变量。

unset GIT_DIR

I think you want this:

cd /home/demo/public_html/example.com/public/ && git status

The backticks are used to capture the output of a command in shell variable, for example:

x=`ls`

will put the output of ls into the variable x .

Are you actually including the backquotes around git status ? That is, are you writing cd ... && `git status` or cd ... && git status ? If you're writing the first one, then what that's doing is evaluating the git status command, and then trying to interpret the results of that as another command to execute. Remove the backquotes, and you should just get the result of git status , not an error as it tries to interpret its results as a command.

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