markdown 使用git push为项目部署创建一个裸的远程git存储库

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 使用git push为项目部署创建一个裸的远程git存储库相关的知识,希望对你有一定的参考价值。

# Bare Remote git Repository for deployment

## Remote Server Prep

Prepare the working directory and directory for the git repo.
Example is using root login with ssh keybased auth, configured in ssh server.

``` bash
# mkdir -p /root/repo/projectname.git
# mkdir -p /var/www/projectname/public_html
```
Initialize bare git repo in the git repo dir and setup post-receive hook

```bash
# cd /root/repo/projectname.git
# git init --bare
# vim hooks/post-receive
# chmod +x hooks/post-receive
```

post-receive is an executable file containing bash script as follows;

```bash
Content of hooks/post-receive

#!/bin/sh
git --work-tree=/var/www/projectname/public_html --git-dir=/root/repo/projectname.git/ checkout -f
chown -R www-data.www-data /var/www/projectname/public_html
```
Notice the additional chown command so the ownership of the pushed data changed to www-data user, not recommended for a large project, need to find another method.

## Development Machine prep

In the local machine ssh is configured to login to remote server via ~/.ssh/config file as follows:

``` bash
Content of ~/.ssh/congfig file

Host project
        Hostname server.ip.address
        Port 22
        User root
        IdentityFile ~/.ssh/keyfilepath
```
So we can login to remote server using ssh only with an alias such as `ssh project`;

Create the directory for the local project development, init local git repo and add remote git repo

``` bash
$ mkdir ~/Project/www-deploy/ && ~/Project/www-deploy
$ git init .
$ git remote add remote ssh://project/root/repo/project.git
$ touch .gitignore
$ git add .
$ git commit -m "Initial commit"
$ git push remote master

```

以上是关于markdown 使用git push为项目部署创建一个裸的远程git存储库的主要内容,如果未能解决你的问题,请参考以下文章

用 GitBook 创建一本书

如何禁止GitLab分支被push

markdown 在`git push`之后在本地和远程撤消`git commit`

Git----使用WebHook实现代码自动部署

使用git部署服务器

无法为本地存储库头运行 aws.push