当前位置 : 主页 > 操作系统 > centos >

Git克隆GitLab以及Git本地仓库上传GitLab

来源:互联网 收集:自由互联 发布时间:2021-04-07
首先确保本机已经安装上Git,其次确认可以正常访问Gitlab服务器 环境: Git:CentOS 7.x 192.168.126.138 Gitlab: CentOS 7.x 192.168.126.137 1:填写Gitlabn仓库信息 登陆到Gitlab服务器地址,新建仓库

首先确保本机已经安装上Git,其次确认可以正常访问Gitlab服务器

 环境:

  Git:CentOS 7.x  192.168.126.138

  Gitlab: CentOS 7.x 192.168.126.137

 1:填写Gitlabn仓库信息

  登陆到Gitlab服务器地址,新建仓库

创建成功后会自动跳转至该仓库的页面:

上面红色框内,是仓库地址,我们尝试把仓库克隆到本地仓库:

[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

编写一个新文件:

[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.

查看下Web端的Accommate:

(上传文件前)

(上传文件后)刷新下web页面:

 查看下是不是我们之前写的内容:

 注:如果上传至Github,需要定义SSH-Key

网友评论