部署git服务器踩坑记

git客户端用起来很方便 但是部署git服务器其实有很多坑的 很多地方搜都搜不到 于是我写这篇文章希望能帮到你

-> 部署Git服务端

安装SSH

云主机普遍自带 这里就不说了

安装Git

安装Git

sudo apt-get install git

新建Git用户

新建一个用户
然后 禁用这个用户的 bash 改成 git-shell

adduser git

这一步密码记住

vi /etc/passwd

最下面找到这行

git:x:1000:1000:,,,:/home/git:/bin/bash

改成

git:x:1000:1000:,,,:/home/git:/usr/bin/git-shell

ok搞定

-> 使用Git服务端

把一个文件夹变成仓库

以/home/git/test为例

1.把这个文件夹给git用户

chown -R git:git /home/git/test

2.进入文件夹 输入git init 新建仓库

cd /home/git/test
git init

这个时候 这个git是空的 即使这个文件夹不是空的

3.把文件夹里面的东西添加进git仓库

git add .
git commit -a -m "hello git"

OK搞定

-> 客户端 连接Git服务端

【rsa公钥私钥不是必须,密码也可以】

以服务器ip为1.2.3.4为例

  • 关联并拉取
git remote add origin git@1.2.3.4:/home/git/test
git pull origin master

然后会提示输入密码 密码就是新建git用户时设的密码

  • 更新提交
git add .
git commit -a -m "hello git"
git push --set-upstream origin master

这样的提交 会报错

remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error: 
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
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 some
remote: error: other way.
remote: error: 
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.

需要在服务端这样配置

git config receive.denyCurrentBranch ignore

然后再提交就ok了

提交完了 到服务器上看 刚传的的东西都没有的 什么都没变

需要在服务端

git reset --hard

才能看到

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值