1. 程式人生 > >碼雲代碼托管平臺使用教程

碼雲代碼托管平臺使用教程

客戶 安全加密 使用教程 strong 目的 one vpd ssh key can

常見的代碼托管平臺,國外的有github,國內的有碼雲、coding.net等。這裏介紹碼雲代碼托盤平臺使用(其它平臺方法類似)。


一、註冊碼雲帳號

https://gitee.com/signup

技術分享圖片


二、創建項目

技術分享圖片


技術分享圖片


三、客戶端創建ssh key

ssh可以讓客戶端與碼雲服務器安全加密連接,而且不需要輸入密碼。

1、客戶端生成公鑰和私鑰。

[root@localhost ~]# ssh-keygen -t rsa -C "[email protected]"
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
64:78:e9:5d:72:d0:d5:0c:51:f9:dc:25:ff:b5:5b:d9 [email protected]
The key's randomart image is:
+--[ RSA 2048]----+
|          .. .+*o|
|       . . .. ..+|
|      . = . o  ++|
|       = . +    *|
|        S .     *|
|               oE|
|                o|
|               . |
|                 |
+-----------------+


2、查看生成的公鑰。

[root@localhost ~]# cat ~/.ssh/id_rsa.pub


3、將公鑰復制到碼雲這裏。

技術分享圖片


4、測試是否可以連接到碼雲服務器。

[root@localhost ~]# ssh -T [email protected]
The authenticity of host 'git.oschina.net (116.211.167.14)' can't be established.
RSA key fingerprint is e3:ee:82:78:fb:c0:ca:24:65:69:ba:bc:47:24:6f:d4.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'git.oschina.net,116.211.167.14' (RSA) to the list of known hosts.
Welcome to Gitee.com, 賽裏! -----看到這句表示成功



四、客戶端(本地)初始化一個項目

1、首先設置你的姓名和郵箱地址,提交代碼的時候會記錄這些信息。

[root@localhost ~]# git config --global user.name "gxm"
[root@localhost ~]# git config --global user.email "[email protected]"


2、創建目錄並初始化成版本庫

[root@localhost ~]# mkdir gxmscript
[root@localhost ~]# cd gxmscript
[root@localhost gxmscript]# git init
Initialized empty Git repository in /root/gxmscript/.git/


3、運行如下命令(支持https和ssh方式)。

[root@localhost gxmscript]# git remote add origin [email protected]:null_803_3682/service_montir.git

技術分享圖片


備註1:如果輸入錯了,可以用如下命令刪除,然後重新運行上面的命令(沒輸錯不要看以下灰色的幾行)。

[root@localhost gxmscripts]# git remote -v
[root@localhost gxmscripts]# git remote rm origin
[root@localhost gxmscripts]# git remote -v
[root@localhost gxmscript]# git remote add origin [email protected]:null_803_3682/service_montir.git

備註2:如果要克隆項目運行git clone 項目地址


4、進入已經初始化或者克隆項目的目錄

因為碼雲服務器上有README.md這個文件,而本地沒有,所以提交的時候可能會沖突。這個時候需要選擇是保留碼雲服務器上這個文件,還是舍棄?如果舍棄用這個命令強制推送(git push origin master -f)。而如果需要保留先執行git pull origin master從碼雲服務器拉過來(或者用git clone克隆下來)。我這裏選擇保留的方法。

[root@localhost gxmscript]# git pull origin master
The authenticity of host 'gitee.com (116.211.167.14)' can't be established.
RSA key fingerprint is e3:ee:82:78:fb:c0:ca:24:65:69:ba:bc:47:24:6f:d4.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'gitee.com' (RSA) to the list of known hosts.
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From gitee.com:null_803_3682/service_montir
 * branch            master     -> FETCH_HEAD
[root@localhost gxmscript]# ll
總用量 4
-rw-r--r-- 1 root root 81 5月  22 03:26 README.md


5、提交一個程序(腳本)。

[root@localhost gxmscript]# vi service_montir.sh
[root@localhost gxmscript]# git add service_montir.sh 
[root@localhost gxmscript]# git commit -m "提交服務監控腳本"
[master 95ce665] 提交服務監控腳本
 1 files changed, 112 insertions(+), 0 deletions(-)
 create mode 100644 service_montir.sh
 
[root@localhost gxmscript]# git status
# On branch master
nothing to commit (working directory clean)

[root@localhost gxmscript]# git log
commit 95ce665342fff8a14d50293877c635e35700ed92
Author: gxm <[email protected]>
Date:   Sun May 22 03:30:00 2016 +0800
    提交服務監控腳本
commit e819f6818e1bd10f730278028603df81183ca30c
Author: 賽裏 <[email protected]>
Date:   Sat Feb 3 10:48:42 2018 +0800
    Initial commit
    
[root@localhost gxmscript]# git push origin master
Counting objects: 4, done.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 1.28 KiB, done.
Total 3 (delta 0), reused 0 (delta 0)
To [email protected]:null_803_3682/service_montir.git
   e819f68..95ce665  master -> master


6、登錄到碼雲服務器進程驗證,提交成功。

技術分享圖片

碼雲代碼托管平臺使用教程