Git如何克隆Gitlab?Git本地仓库如何上传Gitlab?
首先确保本机已经安装上Git,其次确认可以正常访问Gitlab服务器
环境:
Git:Centos 7.x 192.168.126.138
Gitlab: Centos7.x 192.168.126.137
1:填写Gitlabn仓库信息
登陆到Gitlab服务器地址,新建仓库
创建成功后会自动跳转至该仓库的页面:
2:clone克隆仓库到本地
上面红色框内,是仓库地址,我们尝试把仓库克隆到本地仓库:
[root@localhost 123]#git clone http://192.168.126.137/root/Accommate.git #192.168.126.137是指Gitlab服务器地址,可以修改成域名,看自己爱好
Cloning into 'Accommate'...
Username for 'http://192.168.126.137': root #Gitlab 账号
Password for 'http://root@192.168.126.137': #Gitlab 密码
warning: You appear to have cloned an empty repository.
将该Gitlab版本仓库添加到本机的远程列表中:
[root@localhost Accommate]# git remote add Accommate git@192.168.126.137:root/Accommate.git
[root@localhost Accommate]# git remote
Accommate
goodboys
origin
3:提交文件至gitlab
编写一个新文件:
[root@localhost /]# cd Accommate/ [root@localhost Accommate]# echo "This is Test txt - Accommate" > accommate
将该文件提交到本地的Git版本仓库:
[root@localhost Accommate]# git add accommate [root@localhost Accommate]# git commit -m "add accommate" [master (root-commit) 743413d] add accommate 1 file changed, 1 insertion(+) create mode 100644 accommate
然后将本地的Git仓库同步到远程Git服务器上(第一次请加上参数-u,代表关联本地与远程):
[root@localhost Accommate]# git push -u origin master Username for 'http://192.168.126.137': root #Gitlab 账号 Password for 'http://root@192.168.126.137': #Gitlab 密码 Counting objects: 3, done. Writing objects: 100% (3/3), 238 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) To http://192.168.126.137/root/Accommate.git #上传的仓库 * [new branch] master -> master Branch master set up to track remote branch master from origin.
4:查看上传文件
查看下Web端的Accommate:
(上传文件前)
(上传文件后)刷新下web页面:
查看下是不是我们之前写的内容:
注:如果上传至Github,需要定义SSH-Key