简体   繁体   English

服务器上的中央git repo,从中推送和拉出

[英]Central git repo on server, push and pull from it

This could very well be a duplicate question, but I just can't find a satisfying answer to my question. 这很可能是一个重复的问题,但是我只是找不到一个令人满意的答案。 The situation is this, I've got a webserver which I can talk to over ssh and it has git installed. 情况是这样,我有一个Web服务器,可以通过ssh与之对话,并且已经安装了git。 There is a folder on it that represends a website. 上面有一个文件夹,代表一个网站。 Previously, everyone would just work on the server at the same time (via FTP) or download a copy to there machine, work on it there, and FTP it back. 以前,每个人都可以同时在服务器上工作(通过FTP),或者将副本下载到该计算机上,在该计算机上工作,然后通过FTP返回。

What I want now, is make that folder a git repo, which people can clone to there local machine. 我现在想要的是将该文件夹设为git repo,人们可以将其克隆到本地计算机上。 Work on it, and push the changes back to the server. 对其进行处理,然后将更改推回服务器。

How do I do this? 我该怎么做呢? I've tried just creating a repo on the server. 我试过只在服务器上创建一个回购。 I can clone this repo, but can't push anything to it. 我可以克隆此存储库,但不能执行任何操作。 I've read some things about a bare git repo, but it seems to me this doesn't work for my problem, because I want the repo on the server to be the actual website folder and files. 我已经阅读了一些有关裸git repo的内容,但是在我看来这对我的问题不起作用,因为我希望服务器上的repo是实际的网站文件夹和文件。

I really hope someone can help, or point me in the right direction. 我真的希望有人可以提供帮助,或为我指明正确的方向。

Thanks in advance! 提前致谢!

Start here: http://git-scm.com/book/en/Git-on-the-Server . 从这里开始: http : //git-scm.com/book/en/Git-on-the-Server This document is widely available and very comprehensive, covering everything about setting up a git server. 该文档广泛可用并且非常全面,涵盖了有关设置git服务器的所有内容。

I really suggest to separate the git repository from the deployment directory. 我真的建议将git存储库与部署目录分开。

Pushing to the server the repository and deploying in production a new version of your sites must obey to different workflow. 将存储库推送到服务器并在生产环境中部署新版本的站点必须遵循不同的工作流程。 In fact you should push to the git repository many times per day... 实际上,您应该每天多次推送到git存储库...

Given that you already have ssh access, you should simply 鉴于您已经具有ssh访问权限,则只需

  • use a bare repository, in the standard way you found 以您发现的标准方式使用裸仓库
  • build a one line deployment script based on scp or rsync (of course you should commit this script) and execute this script from one of the development computers 基于scp或rsync构建一个单行部署脚本(当然,您应该提交此脚本),并从其中一台开发计算机执行此脚本

EDIT : 编辑:

here's an example of a one line deployement script for a web site : 这是一个网站的单行部署脚本示例:

rsync -avz --del --stats --exclude="deploy.sh" /path/Chrall/web/* someid@someweb.org:/var/www/canop/chrall

And I use usually slightly more complex (4 or 5 lines and a config) scripts in real projects (ref one of my github repositories ). 在实际项目中,我通常使用稍微复杂一些的脚本(4或5行和一个配置)(请参阅我的github存储库之一 )。

Simple howto for preparing git deployment of web: 准备Web的git部署的简单方法:

  • Prepare list of files, which should not be shared - temp and data directories - into file .gitignore in directory on web server, which should begin to be shared: 将不应该共享的文件列表(临时目录和数据目录)准备到Web服务器目录中的文件.gitignore中,应开始共享:

     cd /var/www/mydomain.org/ echo temp >> .gitignore echo data >> .gitignore 
  • Initiate git repository in this directory: 在以下目录中启动git仓库:

     git init git add -A git commit -m "Init" 
  • Allow pushing into this repository, though it is not bare repository: 允许推入该存储库,尽管它不是裸存储库:

     git config receive.denycurrentbranch false 
  • Add hook to set working tree to current version when new version is pushed - this script will be started after pushing: 添加挂钩以在推送新版本时将工作树设置为当前版本-推送后将启动以下脚本:

     echo '#!/bin/sh' > .git/hooks/post-receive echo 'git checkout -f' >> .git/hooks/post-receive echo 'git reset --hard' >> .git/hooks/post-receive chmod +x .git/hooks/post-receive 

Now should be server prepared, now you can clone repository to client and push back normally. 现在应该已经为服务器做好了准备,现在您可以将存储库克隆到客户端并正常推回。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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