gitlab上傳公鑰和項目代碼

gitlab上傳項目須要ssh公鑰免交互,本文介紹gitlab設置公鑰和上傳項目的操做。git


1、建立祕鑰對web

[root@localhost ~]# ssh-keygen -t rsa   #一路回車便可ssh

Z73_ENY~}GTCIXVF`5@[6M8.png


2、上傳祕鑰ide

[root@localhost ~]# cat ~/.ssh/id_rsa.pub   #查看公鑰gitlab

2上傳公鑰.png


3、上傳本地代碼fetch

一、要先設置用戶和郵箱this

[root@localhost opt]# git config --global user.name "root"code

[root@localhost opt]# git config --global user.email "w135xxxxx@qq.com"blog

[root@localhost opt]# git config --listrem

user.name=root

user.email=w135xxxx@qq.com


二、建立一個本地代碼倉庫

[root@localhost opt]# mkdir push_code

[root@localhost opt]# cd push_code/


三、初始化該倉庫

[root@localhost push_code]# git init 

初始化空的 Git 版本庫於 /opt/pull_code/.git/

[root@localhost push_code]# echo "this is test push code" > push.txt

[root@localhost push_code]# ls

pull.txt


四、獲取分支

#這個分支信息,能夠在web界面clon裏看到

[root@localhost push_code]# git remote add origin http://192.168.0.8:81/test/hellow.git


五、刷新遠程倉庫分支

[root@localhost push_code]# git fetch origin --prune

#獲取全部遠程分支

#如今處於master分支

[root@localhost push_code]# git branch -a

  0a

* master

  remotes/origin/devops

  remotes/origin/master


六、提交代碼

#提交文件到本地倉庫

[root@localhost push_code]# git add push.txt     #添加文件

[root@localhost push_code]# git commit -m "this is test push"    #添加說明

[root@localhost push_code]# git push  origin master    #推送代碼至master分支

#小坑

[root@localhost push_code]# git push  origin master

Username for 'http://192.168.0.8:81': root

Password for 'http://root@192.168.0.8:81': 

To http://192.168.0.8:81/test/hellow.git

 ! [rejected]        master -> master (non-fast-forward)

error: 沒法推送一些引用到 'http://192.168.0.8:81/test/hellow.git'

提示:更新被拒絕,由於您當前分支的最新提交落後於其對應的遠程分支。

提示:再次推送前,先與遠程變動合併(如 'git pull')。詳見

提示:'git push --help' 中的 'Note about fast-forwards' 小節。

#解決:從新拉取遠程代碼倉庫信息,與遠程倉庫代碼信息保持一致

[root@localhost push_code]# git pull http://192.168.0.8:81/test/hellow.git

Username for 'http://192.168.0.8:81': root

Password for 'http://root@192.168.0.8:81': 

來自 http://192.168.0.8:81/test/hellow

 * branch            HEAD       -> FETCH_HEAD

已是最新的!


七、切換分支

[root@localhost push_code]# git checkout devops

分支 devops 設置爲跟蹤來自 origin 的遠程分支 devops。

切換到一個新分支 'devops'

[root@localhost push_code]# git branch -a

* devops

  master

  remotes/origin/devops

  remotes/origin/master

其餘分支上傳代碼方式相同重複步驟6便可


八、拉取指定分支代碼

git clone  -b devops http://192.168.0.8:81/test/hellow.git     #-b指定拉取分支的代碼


九、建立分支

git branch slave 建立slave分支

相關文章
相關標籤/搜索