码云代码托管平台使用教程

本文涉及的产品
云服务器 ECS,每月免费额度280元 3个月
云服务器ECS,u1 2核4GB 1个月
简介:

常见的代码托管平台,国外的有github,国内的有码云、coding.net等。这里介绍码云代码托盘平台使用(其它平台方法类似)。


一、注册码云帐号

https://gitee.com/signup

图片.png


二、创建项目

图片.png


图片.png


三、客户端创建ssh key

ssh key可以让客户端与码云服务器安全加密连接,而且不需要输入密码。

1、客户端生成公钥和私钥。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[root@localhost ~] # ssh-keygen -t rsa -C "442102293@qq.com"
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 442102293@qq.com
The key's randomart image is:
+--[ RSA 2048]----+
|          .. .+*o|
|       . . .. ..+|
|      . = . o  ++|
|       = . +    *|
|        S .     *|
|               oE|
|                o|
|               . |
|                 |
+-----------------+


2、查看生成的公钥。

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


3、将公钥复制到码云这里。

图片.png


4、测试是否可以连接到码云服务器。

1
2
3
4
5
6
[root@localhost ~] # ssh -T git@git.oschina.net
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、首先设置你的姓名和邮箱地址,提交代码的时候会记录这些信息。

1
2
[root@localhost ~] # git config --global user.name "gxm"
[root@localhost ~] # git config --global user.email "gxm@test.com"


2、创建目录并初始化成版本库

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


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

1
[root@localhost gxmscript] # git remote add origin git@gitee.com:null_803_3682/service_montir.git

图片.png


备注1:如果输入错了,可以用如下命令删除,然后重新运行上面的命令(没输错不要看以下灰色的几行)。

1
2
3
4
[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 git@gitee.com:null_803_3682/service_montir.git

备注2:如果要克隆项目运行git clone 项目地址


4、进入已经初始化或者克隆项目的目录

因为码云服务器上有README.md这个文件,而本地没有,所以提交的时候可能会冲突。这个时候需要选择是保留码云服务器上这个文件,还是舍弃?如果舍弃用这个命令强制推送(git push origin master -f)。而如果需要保留先执行git pull origin master从码云服务器拉过来(或者用git clone克隆下来)。我这里选择保留的方法。

1
2
3
4
5
6
7
8
9
10
11
[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
1
2
3
[root@localhost gxmscript] # ll
总用量 4
-rw-r--r-- 1 root root 81 5月  22 03:26 README.md


5、提交一个程序(脚本)。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
[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 <gxm@ test .com>
Date:   Sun May 22 03:30:00 2016 +0800
     提交服务监控脚本
commit e819f6818e1bd10f730278028603df81183ca30c
Author: 赛里 <442102293@qq.com>
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 git@gitee.com:null_803_3682 /service_montir .git
    e819f68..95ce665  master -> master


6、登录到码云服务器进程验证,提交成功。

图片.png




本文转自 sailikung 51CTO博客,原文链接:http://blog.51cto.com/net881004/2068419,如需转载请自行联系原作者

相关实践学习
一小时快速掌握 SQL 语法
本实验带您学习SQL的基础语法,快速入门SQL。
7天玩转云服务器
云服务器ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,可降低 IT 成本,提升运维效率。本课程手把手带你了解ECS、掌握基本操作、动手实操快照管理、镜像管理等。了解产品详情:&nbsp;https://www.aliyun.com/product/ecs
相关文章
|
3月前
|
Shell 程序员 开发工具
码云代码托管平台
码云代码托管平台
|
6月前
|
缓存 程序员 开发工具
服务搭建篇(八) 使用GitLab部署一个属于自己的代码托管平台
服务启动完成后,就可以访问gitlab服务了。默认的服务端口就是80端口。默认的用户名和密码是 root/123456(通常建议登录后立即修改默认密码)
191 0
|
6月前
|
存储 Linux Go
【git】安装体验Gitea 代码托管平台
【git】安装体验Gitea 代码托管平台
203 0
|
10月前
|
开发工具 git
如何把其他代码托管平台git仓库迁移到github还保留历史日志记录?图解步骤,值得收藏!
我在其他的代码托管平台(不是github)有一套代码,不同代码托管平台之间没有相互迁移的功能,怎么将仓库代码提交到github仓库呢?我会讲解适合于所有不同托管平台Git仓库之间的迁移方法,所以就不要老是抱怨着为什么没有外部仓库迁移过来的功能了。
216 0
如何把其他代码托管平台git仓库迁移到github还保留历史日志记录?图解步骤,值得收藏!
|
Docker 容器
『GitLab』在Docker中快速部署GitLab私有代码托管平台
📣读完这篇文章里你能收获到 - 在Docker中快速部署Gitlab
360 0
『GitLab』在Docker中快速部署GitLab私有代码托管平台
|
网络安全 开发工具 git
远程代码托管平台--GitHub、Gitee的使用(2)
远程代码托管平台--GitHub、Gitee的使用(2)
192 0
远程代码托管平台--GitHub、Gitee的使用(2)
|
Linux 网络安全 开发工具
远程代码托管平台--GitHub、Gitee的使用(1)
远程代码托管平台--GitHub、Gitee的使用(1)
494 0
远程代码托管平台--GitHub、Gitee的使用(1)
|
开发工具 git
gitee代码托管平台的基本使用与操作
gitee代码托管平台的基本使用与操作
186 1
gitee代码托管平台的基本使用与操作
《04 卓越三项——阿里巴巴代码托管平台技术揭秘-v13》电子版地址
04 卓越三项——阿里巴巴代码托管平台技术揭秘-v13
56 0
《04 卓越三项——阿里巴巴代码托管平台技术揭秘-v13》电子版地址
|
XML 存储 Java
【Git】什么是Git以及码云代码托管服务
本期主要介绍什么是Git以及码云代码托管服务
214 0
【Git】什么是Git以及码云代码托管服务