将centos上现有的项目添加到git版本库

一. linux服务器现有项目添加到版本库

前提服务器搭建好git

cd /www/wwwroot/h5.test.com 
git init 
ls -al

项目里会出现仓库
drwxr-xr-x 7 root root 4096 May 30 18:23 .git

 git add .
git commit -m "first commit"

到本地电脑git 客户端
phper@xx.xxx.xxx.xxx:/www/wwwroot/h5.test.com
尝试新增或者修改内容
git add readme.md
git commit -m “tijiao1”
git push origin master

到了这一步会报错

remote: error:
remote: error: You can set 'receive.denyCurrentBranch' configuration variable t
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing int
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in som
remote: error: other way.
remote: error:
remote: error: To squelch this message and still keep the default behaviour, se
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To xxx.xxx.xxx.xxx:/www/wwwroot/h5.test.com 
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'phper@xxx.xxx.xxx.xxx:/www/wwwroot/h5.test.com '

vim /www/wwwroot/h5.test.com/.git/config
修改.git/config添加如下代码:

[receive]

denyCurrentBranch = ignore

自动部署检出到项目目录
touch /www/wwwroot/h5.test.com/.git/post-receive
chown phper:git post-receive 

post-receive内容
git --work-tree=/www/wwwrooth5.test.com /
–git-dir=/www/wwwroot/h5.test.com /.git checkout -f


chmod +x post-receive

chwon -R phper:git h5.test.com/

再次提交

 git push origin master
Counting objects: 6, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (6/6), 483 bytes | 0 bytes/s, done.
Total 6 (delta 2), reused 0 (delta 0)
To 60.205.249.232:/www/wwwroot/h5.test.com 
   52711fe..6018ecb  master -> master

忽略某个已经托管给git的文件,防止二次提交

# 执行命令将文件加入不提交队列

git update-index --assume-unchanged 你的文件路径

# 执行命令将文件取消加入不提交队列

git update-index --no-assume-unchanged 你的文件路径

参考

禁止客户端shell登录
因为前面我们添加了客户端的ssh的公钥到远程服务器,所以客户端可以直接通过shell远程登录服务器,这不安全,也不是我们想要的。且看下面如何禁用shell登录

mkdir /home/phper/git-shell-commands

#phper:x:1002:1003::/home/phper:/bin/bash
phper:x:1002:1003::/home/phper:/bin/git-shell

参考

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值