首頁 > 軟體

Git克隆GitLab以及Git本地倉庫上傳GitLab

2020-06-16 16:39:00

首先確保本機已經安裝上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


IT145.com E-mail:sddin#qq.com