简体   繁体   中英

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. 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.

What I want now, is make that folder a git repo, which people can clone to there local machine. 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.

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 . This document is widely available and very comprehensive, covering everything about setting up a git server.

I really suggest to separate the git repository from the deployment directory.

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...

Given that you already have ssh access, you should simply

  • 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

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

Simple howto for preparing git deployment of web:

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

     cd /var/www/mydomain.org/ echo temp >> .gitignore echo data >> .gitignore 
  • Initiate git repository in this directory:

     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.

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