第一次搭建自己的GIT
2013-11-10 17:35
471 查看
1、sudo apt-get update
sudo apt-get upgrade
(参考文档 中说要执行 sudo apt-get install openssh-server
我本地以前 执行过 sudo apt-get install ssh,经常用ssh,所以执行时,提示已装安装)
2、个人比较懒,ssh/sshd_confi用了默认配置
如果修改,需要重启的才生效
sudo /etc/init.d/ssh restart
修改ssh服务端配置文件 /etc/ssh/sshd_confi
3、安装git,经常用github 所以这一步也省去了
sudo apt-get install git-core
4、安装gitosis
git clone https://github.com/res0nat0r/gitosis.git
cd gitosis
sudo python setup.py install
注意:如果python setup.py install失败,需要安装python-setuptools.py
在我本机 是sudo apt-get install python-setuptools
不是是sudo apt-get install python-setuptools.py
5. 为gitosis创建系统用户 (当前用户为jason)
sudo adduser --system --shell /bin/sh --gecos 'git SCM user' --group --disabled-password --home /home/git git
这种方法是网上比较常见的方法,创建的是一个禁用密码的git用户,但在使用su命令切换git用户的时候,空密码老是
验证失败,大家可以使用下面的方法来创建git用户:
sudo useradd -m git
sudo password git
6.运行gitosis(当前用户为jason)
A和B部分选其一测试
A部分
1、 ssh-keygen一直回车即可
2、 ssh-copy-id git@127.0.0.1
以上两步详细解析见http://hi.baidu.com/springwu/item/b36f08d54ede10ba33db90c9
B部分
(1)将管理员生成的公钥上传或拷贝到服务器上。这里的公钥需要在git服务器管理员下使用ssh-keygen -t rsa命令来创建,
网上流传的方法是scp /your pub_path/id_rsa.pub ${SERVER_IP}:id_rsa.pub。我们这里使用的是直接U盘拷贝的方法。
(2)初始化gitosis
进入到拷贝过来的id_rsa.pub所在目录:cd /tmp
sudo chmod 777 id_rsa.pub
sudo -H -u git gitosis-init < id_rsa.pub (或者切换到git用户下执行gitosis-init < id_rsa.pub也可以,记得exit切换回当前用户)
此时,会在/home/git目录下生成一些目录,如果想要别人能够clone gitosis-admin.git,需要执行以下操作:
sudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update
至此,gitosis的安装工作已完成,其相关配置可以有管理员来操作,然后再提交到服务器上。以下是关于gitweb的安装配置,
7. 创建自己的仓库
su git
/home/git
$ mkdir test.git
$ cd test.git
$ git init --bare
Initialized empty Git repository in /home/git/test.git/
8.获取刚才创建的库
jason@jason-lxw:~/test_git$ cd test3/
jason@jason-lxw:~/test_git/test3$ git clone git@127.0.0.1:test.git
Cloning into 'test'...
warning: You appear to have cloned an empty repository.
到这里已经可使用了
9。继续测试
jason@jason-lxw:~/test_git/test3$ echo "hello" >hello
jason@jason-lxw:~/test_git/test3$ ls
hello test
jason@jason-lxw:~/test_git/test3$ mv hello test/
jason@jason-lxw:~/test_git/test3$ ls
test
jason@jason-lxw:~/test_git/test3$ cd test/
jason@jason-lxw:~/test_git/test3/test$ ls
hello
jason@jason-lxw:~/test_git/test3/test$ git log
fatal: bad default revision 'HEAD'
jason@jason-lxw:~/test_git/test3/test$ git log hello
fatal: bad default revision 'HEAD'
jason@jason-lxw:~/test_git/test3/test$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
#hello
nothing added to commit but untracked files present (use "git add" to track)
jason@jason-lxw:~/test_git/test3/test$
jason@jason-lxw:~/test_git/test3/test$ git add hello
jason@jason-lxw:~/test_git/test3/test$ git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
#new file: hello
#
jason@jason-lxw:~/test_git/test3/test$ git commit -m "first add" hello
[master (root-commit) 42623fe] first add
1 file changed, 1 insertion(+)
create mode 100644 hello
jason@jason-lxw:~/test_git/test3/test$ git status
# On branch master
nothing to commit (working directory clean)
jason@jason-lxw:~/test_git/test3/test$ git push origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 211 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@127.0.0.1:test.git
* [new branch] master -> master
jason@jason-lxw:~/test_git/test3/test$ git log
commit 42623fe199b4c507d4834e351878416f522ea462
Author: jason <langxianzhe@gmail.com>
Date: Fri Jun 7 11:04:17 2013 +0800
first add
jason@jason-lxw:~/test_git/test3/test$ git log hello
commit 42623fe199b4c507d4834e351878416f522ea462
Author: jason <langxianzhe@gmail.com>
Date: Fri Jun 7 11:04:17 2013 +0800
first add
jason@jason-lxw:~/test_git/test3/test$ vi hello
jason@jason-lxw:~/test_git/test3/test$ git commit -m "add world" hello
[master 4845e74] add world
1 file changed, 1 insertion(+)
jason@jason-lxw:~/test_git/test3/test$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
#hello~
nothing added to commit but untracked files present (use "git add" to track)
jason@jason-lxw:~/test_git/test3/test$ git diff
jason@jason-lxw:~/test_git/test3/test$ git diff hello
jason@jason-lxw:~/test_git/test3/test$ git push origin master
Counting objects: 5, done.
Writing objects: 100% (3/3), 247 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@127.0.0.1:test.git
42623fe..4845e74 master -> master
jason@jason-lxw:~/test_git/test3/test$ git log hello
commit 4845e74c09b400788794e326f8f493b2e29c4583
Author: jason <langxianzhe@gmail.com>
Date: Fri Jun 7 11:05:49 2013 +0800
add world
commit 42623fe199b4c507d4834e351878416f522ea462
Author: jason <langxianzhe@gmail.com>
Date: Fri Jun 7 11:04:17 2013 +0800
first add
jason@jason-lxw:~/test_git/test3/test$ vi hello
jason@jason-lxw:~/test_git/test3/test$ git diff hello
diff --git a/hello b/hello
index 94954ab..827483f 100644
--- a/hello
+++ b/hello
@@ -1,2 +1,3 @@
hello
world
+!
相关文章推荐
- Windows下第一次使用Git传文件到自己的GitHub
- 如何用git搭建自己的vuex工作环境
- 记录自己在centos虚拟机搭建简易git服务器的过程,分享给大家
- 使用markdown和gitblog搭建自己的博客
- Android Studio 连接自己搭建的server 须要admin 的帐号的问题 SSH Password Login,please enter password for user git@git.
- 利用Git搭建自己的blog
- 在 linux 上搭建自己的 git 服务器
- 自己搭建Git服务器实现SSH以及远程仓库迁移
- 使用gitlab+git+mysql+redis+nginx搭建自己的代码管理平台
- 搭建自己的Git服务器
- 在CentOS下搭建自己的Git服务器
- 在CentOS下搭建自己的Git服务器
- 使用markdown和gitblog搭建自己的博客
- Git从入门到放弃——GitHub搭建自己的博客篇
- 使用 Gogs 搭建自己的 Git 服务器,详见网址
- 阿里云Linux CentOS 7 Docker部署使用gogs搭建自己的git服务器
- 在CentOS下搭建自己的Git服务器
- 在vps上搭建自己的git服务器gogs
- 搭建自己的Git服务器失败了
- 使用 Gogs 搭建自己的 Git 服务器