作者:fbysss
QQ:溜酒酒吧酒吧吾散
blog:blog.csdn.net/fbysss
声明:本文由fbysss原创,转载请注明出处
一、git安装
Centos下面,就是这么任性:
yum install git
中间有2步需要输入y确认一下。
其他操作系统方法:http://git-scm.com/download/linux
安装完成后,
git --version
git version 1.7.1
验证成功。
二、.gitlab安装
GitLab是很接近Github的,而且免费,所以选择它作为项目代码仓库。地址:https://about.gitlab.com/downloads/
选择操作系统之后,会有一步步的提示。当然,有些已经有了的,就不用再安装了。可以用whereis检查一下
(curl的-O指的是把url这里的东西直接输出到文件中,文件名默认就是url中的文件名。)
sudo rpm -igitlab-7.6.2_omnibus.5.3.0.ci-1.el6.x86_64.rpm
sudo gitlab-ctl reconfigure
sudo lokkit -s http -s ssh
这句是用来做防火墙的。避免用户通过ssh方式和http来访问
按照步骤做了之后,访问http://localhost就可以进入登录界面了。
默认账号:
Username: root
Password: 5iveL!fe
进去之后就要设置新的密码,随便写一个sss54321
进来之后,可以create a new project
然后会发现,硬盘上已经生成了一个git文件: /var/opt/gitlab/git-data/repositories/root/sssApp.git
也看到了url http://localhost.localdomain:9999/root/sssApp.git
此时,在客户机中,也可以clone一下试试:
git clone http://192.168.0.12:9999/root/sssApp.git
正常。warning: You appear to have cloned an empty repository.很显然,啥也没有,只是一个空仓库。
/opt/gitlab/embedded/etc/gitconfig
[sss@localhost ~]$sudo git config --list
fatal: error processing config file(s)
touch ~/.gitconfig
OK。
——自己装过一个git,gitlab也内嵌一个。但两者显然没有关联。安装好了居然没有配置文件?啥情况。
实际上也无所谓,只不过提示信息太吓唬人了。
rm ~/.gitconfig
git config--global color.diff auto
然后再看,文件已经自动生成了。
三、创建代码仓库:
su root
mkdir /repo/sssApp
cd /repo/sssApp
git init
git remote add originhttp://localhost.localdomain:9999/root/sssApp.git
git push -u origin master
error: The requested URL returned error: 401 Unauthorized while accessing http://localhost.localdomain:9999/root/sssApp.git/info/refs
git config--list发现 remote.origin.url=http://localhost.localdomain:9999/root/sssApp.git
git config -e可以进行修改
网上很多帖子说,升级版本之后就OK,或者换SSH方式,在我看来都是不知其所以然。
其实错误提示的已经很清楚了,就是需要认证。
这啦唯一需要大家注意的,就是这里的用户名,应该是gitlab的用户名,与linux主机无关。
正确的做法:
将 remote.origin.url=http://localhost.localdomain:9999/root/sssApp.git
修改为 remote.origin.url=http://root:rootpassword@localhost.localdomain:9999/root/sssApp.git
再试就OK了。
但是问题又来了,这样把密码明文写在这里,显然不是太好。
重新来一遍,新建一个目录和库
mkdir /repo/justtest
cd /repo/justtest
git init
git remote add origin http://root@localhost.localdomain:9999/root/justtest.git
git push -u origin master
(gnome-ssh-askpass:5430):Gtk-WARNING **: cannot opendisplay:
看来是显示的问题。于是直接到Centos下,进入终端执行
这下弹出一个图形化窗口,要我输入密码。
但输入之后提示
error: src refspec master does not match any.
error: failed to push some refsto'http://root@localhost.localdomain:9999/root/