Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
How to set up your own private Git server on Linux


sudo apt-get update
sudo apt-get install git-core


sudo adduser git
sudo mkdir /home/git/.ssh
sudo cp ~/.ssh/authorized_keys /home/git/.ssh/
sudo chown -R git:git /home/git/.ssh
sudo chmod 700 !$
sudo chmod 600 /home/git/.ssh/*

3.用git账户登录,ssh, 如果不能登录,大部分是权限问题, 请检查.ssh和下面文件的权限和归属。 如/etc/passwd 中git用户的$HOME 目录不对等。


mkdir myrepo.git
cd !$
git --bare init

5.通过git hooks的方式当提交时自动checkout仓库代码到指定目录,(还是在服务器上)

cd myrepo.git
# 创建hooks/post-receive并加入以下内容
cat hooks/post-receive

GIT_WORK_TREE=/home/app/quicklisp/local-projects/myapp git checkout -f

# 添加执行权限
chmod +x hooks/post-receive
# 创建 GIT_WORK_TREE 目录, 如果不存在git不会自动创建,并且该目录要求git用户有读写的权限。
mkdir /home/app/quicklisp/local-projects/myapp


git remote add origin
git push origin master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment