进入服务器目录
键入
git init --bare work.git
生成git目录
创建git用户组和用户
groupadd git
useradd git -g git
#添加git到 www用户组中
usermod -G www git
创建证书登录
收集所有需要登录的用户的公钥,公钥位于id_rsa.pub文件中,把我们的公钥导入到/home/git/.ssh/authorized_keys文件里,一行一个。
如果没有该文件创建它:
#2
cd /home/git/
mkdir .ssh
chmod 755 .ssh
touch .ssh/authorized_keys
chmod 644 .ssh/authorized_keys
首先我们选定一个目录作为Git仓库,假定是/home/gitrepo/work.git,在/home/gitrepo目录下输入命令:
cd /home
mkdir gitrepo
chown git:git gitrepo/
cd gitrepo
git init --bare work.git
\#Initialized empty Git repository in /home/gitrepo/work.git/
chown -R git:git work.git
1.4、克隆仓库
$ git clone ssh://git@ip:port/home/gitrepo/work.git
Cloning into ‘learngit’…
warning: You appear to have cloned an empty repository.Checking connectivity… done.
创建推送仓库
进入/home/gitrepo/work.git/hooks
vim post-receive
# 添加以下内容
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/bin/git:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
git --work-tree=/www/wwwroot/yousite.com checkout -f
修改post-receive权限
chmod +x post-receive
设置/www/wwwroot/yousite.com权限
chown git:git -R /www/wwwroot/yousite.com
git push ssh://git@ip@port/home/git/gitrepo/work.git
设置用户名
git config --global user.name "username"
设置邮箱 (没有双引号)
git config --global user.email useremail
查看用户名和密码
git config user.name
git config user.email
查看其他配置信息(git设置列表)
git config --list