Git推到活服务器 [英] Git push to live server

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

问题描述

我们有一个网站,其所有PHP / HTML / JS / CSS / etc文件存储在一个Git存储库中。



我们目前有3种计算机
$ b


  • 本地开发人员:提取最新更改,进行更改,提交本地回购,推送至主服务器

  • 主服务器:中央存储库,所有更改都被推送到主服务器

  • Web服务器:部署网站时,主服务器上的更改被拉下



所以目前我们:

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



所以我的问题是:有没有一种方法可以从我的本地计算机上直接推送到Web服务器?



ie。

  local:git push origin master 
l ocal:密码:********
local:git push webserver master
local:password:********


解决方案

是的,您可以直接推送到您的网络服务器,但我不会推荐它,因为您只应推送到存储库用--bare参数克隆。我会利用git hook系统让主存储库自动更新Web服务器上的repo。查看后更新挂钩:

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



这个脚本可以通过ssh登录到web服务器并做

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

这样您只需要关注推送到中央服务器而不必关心网络服务器,一旦推送完成,它将一直更新。如果你能自动化一些东西,然后自动化:)

我甚至为你发现了一篇关于通过ssh登录脚本的好文章(如果你必须使用密码,这个如果已经设置了ssh-key,那么它是微不足道的):

http://bash.cyberciti.biz/security/expect-ssh-login-script/



希望这帮助!


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

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

  • Local developer: pull latest changes, make changes, commit to local repo, push to master server
  • Master server: central repository, all changes get pushed to the master server
  • Web server: changes are pulled down from the master server when deploying the website

So currently we:

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?

ie.

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

解决方案

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

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 :)

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-login-script/

Hope this helps!

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

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