Git服务器配置 添加用户git
禁用shell登录 1 2 3 4 usermod -s /usr/bin/git-shell git cd /home/git/mkdir git-shell-commands chmod 755 git-shell-commands
其中,登录的publickey位于:1 /home/git/.ssh/authorized_keys
切换用户
初始化git仓库 初始化仓库yatesun
,并对git用户赋权限。1 2 3 cd repositoriesgit init --bare yatesun.git chown git:git yatesun.git -R
克隆工作区1 git clone -bare /home/git/hehe.git hehe
客户端使用Git 客户端Git配置 输入以下命令,可以搭建一个本地的git仓库。1 2 3 4 5 git config --global user.name "Yate Sun" git config --global user.email "yatesun@gmail.com" mkdir git cd gitgit init
客户端从远程仓库克隆 1 git clone git@server:/path/to/yatesun.git
简单测试 1 2 3 4 5 cd yatesunvim readme.md git add readme.md git commit -m "commit first" git push
至此,新编辑的readme.md文件已经成功提交到Git服务器,可以通过以下命令查看Git状态:
更新远程仓库到本地
HTTPS方式 1 2 mv hooks/post-update.sample hooks/post-update git update-server-info
错误处理 问题 1 2 3 4 No refs in common and none specified; doing nothing. Perhaps you should specify a branch such as 'master' . fatal: The remote end hung up unexpectedly error: failed to push some refs to 'git@server:/path/to/code.git'
这是指Git未找到我即将要提交的代码版本。
解决方法