Git如何克隆Gitlab?Git本地倉庫如何上傳Gitlab?


 

 首先確保本機已經安裝上Git,其次確認可以正常訪問Gitlab服務器

 環境:

  Git:Centos 7.x  192.168.126.138

  Gitlab: Centos7.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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM