Git推送到实时服务器 [英] Git push to live server

查看:27
本文介绍了Git推送到实时服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个网站,它的所有 PHP/HTML/JS/CSS/etc 文件都存储在 Git 存储库中.

We have a website that has all its PHP/HTML/JS/CSS/etc files stored in a Git repository.

我们目前有 3 种类型的计算机(或用例)用于存储库.

We currently have 3 types of computers (or use cases) for the repository.

  • 本地开发人员:提取最新更改、进行更改、提交到本地存储库、推送到主服务器
  • 主服务器:中央存储库,所有更改都会推送到主服务器
  • Web 服务器:在部署网站时从主服务器拉取更改

所以目前我们:

local: git push origin master
local: password: ********
local: ssh admin@webserver.com
webserver: password: ********
webserver: cd ~/domain.com/
webserver: git pull origin master

所以我的问题是:有没有办法从我的本地计算机直接推送到网络服务器?

So my question is: is there a way that from my local computer I can push straight to the web server?

即.

local: git push origin master
local: password: ********
local: git push webserver master
local: password: ********

推荐答案

是的,您可以直接推送到您的网络服务器,但我不建议这样做,因为您应该只推送到使用 --bare 参数克隆的存储库.我会利用 git hook 系统让主存储库自动更新 Web 服务器上的存储库.查看 post-update 钩子:

Yes you can push directly to your webserver, but I wouldn't recommend it since you should only push to repositories cloned with the --bare argument. I'd utilize the git hook system to let the main repository automatically update the repo on the web server. Check out the post-update hook in:

http://git-scm.com/docs/githooks

这个脚本可以反过来通过ssh登录web服务器并执行

This script could in turn login to the web server via ssh and do

cd ~/domain.com/
git checkout master
git pull origin master

这样你只需要专注于推送到中央服务器,而不必关心网络服务器,一旦推送完成,它总是会更新.如果你可以自动化一些东西,那就自动化它:)

This way you only need to focus on pushing to the central server and don't have to care about the web server, it will always be updated once a push has been made. If you can automate something, then automate it :)

我什至为您找到了一篇关于在脚本中通过 ssh 登录的好文章(如果您必须使用密码,如果已经设置了 ssh 密钥,这很简单):

I even found a nice article for you about logging in via ssh in a script (if you must use password, this is trivial if a ssh-key has been setup):

http://bash.cyberciti.biz/security/expect-ssh-登录脚本/

希望这有帮助!

这篇关于Git推送到实时服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆