本教程适合对git有一定熟悉能力的人,不熟悉的建议先去用用Github。这里适合个人用户使用,如果是团队或企业用户建议去用更成熟的Gitea或其它产品。
服务器端
- 创建git用户
groupadd git
useradd git -g git
- 服务器禁用shell登录
vim /etc/passwd
git:x:1004:1004::/home/git:/usr/bin/git-shell
- 设定仓库路径
mkdir -p /home/git-repro/git
- 创建裸仓库
cd /home/git-repro/git
git init --bare code.git
本地
- 创建私钥
ssh-keygen -t rsa
- 查看本地私钥
more id_rsa.pub
- 把私钥放到服务器上
vim authorized_keys
- 克隆服务器端仓库
git clone ssh://ssh账号名@域名或者服务器ip:ssh端口号 仓库地址
git clone ssh://[email protected]:9097/home/git-repro/git/code.git
- 其它都和常用git操作一样了
echo "test" >> test.py
git add .
git commit -m 'First commit'
git push
问题
error: src refspec refs/heads/master does not match any
-
这个问题一般前面
git commit -m 'First commit'
有相关报错,如下图:
-
按提示操作即可
git config --global user.email "[email protected]"
git config --global user.name "Your Name"