Pycharm配置Gitee,自己的练习代码也可以版本管理
Git 是大家熟悉的代码版本管理工具,在 GitHub 和 GitLab 上可以托管自己的代码。
但是上面两个网站我们始终访问太慢,所以可以通过国内的 Gitee 等站点来托管自己的练习代码。
本片文章主要梳理一下如何进行相关的配置,让你通过 Pycharm 写的代码能够方便托管到 Gitee 上去。
过程如下:
- 下载并安装
Git
; - 生成 Git 公钥;
- 注册 Gitee 并配置公钥;
- Pycharm 下载 Gitee 插件;
- 配置登录信息;
- 上传代码到 Gitee。
下载安装 Git
本篇以 window 10 安装过程来讲解。
下载 Git
下载 Windows 版本的 Git:
- 进入 Windows版本下载
- 选中 Windows 稳定版:

下载后一路默认安装即可。
安装后,正常情况下会在开始菜单上出现Git GUI Here
,Git Bash Here
。

生成 ssh 密钥
在任意位置右键>Git Bash Here
:

首先配置账号和邮箱,你可以认为有点类似注册:
- 先配置用户名
$ git config --global user.name "17test" # 换成你自己的用户名
- 配置用户邮箱
$ git config --global user.email "email@17test.cn" # 换成你自己的邮箱

接下来生成 SSH 公钥:
$ ssh-keygen -t rsa -C "email@17test.cn" # 换成你自己的邮箱

然后一路回车
即可。
在默认情况下,你可以看到在 C:\Users\你的windows用户名
目录下看到一个 .ssh
文件。

待会我们会用到其中的id_rsa.pub
文件。
注册并配置Gitee
Gitee 是国内的 Git 托管仓库,也就是你用 Git 管理代码,就可以使用 Gitee 作为远程仓库(相当于 SVN 的服务器)。但是一般你提交的代码是公开的,也就是任意人都可以查看并下载你的代码。
如果你不想公开代码,就需要建私有仓库,私有仓库是需要收费的(5人以下的仓库免费)。
登录 Gitee 并注册
配置 Git 的公钥
右键使用记事本打开 Git 安装过程中的id_rsa.pub
。将内容拷贝下来。
- 进入 Gitee 设置界面:

- 配置公钥,公钥内容就是
id_rsa.pub
中的内容,全部拷贝并粘贴。

配置公钥以后,每次提交或拉取代码就不用输账号密码了。
配置 Pycharm
Pycharm 的各种设置,都在 File > Settings
下:

配置 Git

下载Gitee插件
同样在设置页面,选中 Plugins
,并搜索 Gitee
安装。

安装后,重启一下Pycharm。在 Version Control
中会增加 Gitee
选项。
配置Git账号
在上一步新增的Version Control > Gitee
, 添加你的账号密码。

添加账号密码;

大功告成。

至此就基本配置完毕。
项目的上传和下载
项目上传
当你本地建好项目之后,需要上传到 Gitee,可以使用VCS > Share Project on Gitee
,将你的项目分享到 Gitee 上与他人协作。

下一步直接 share;

share 成功后,会在 Gitee 上自动新建一个仓库,并把代码上传。

登录 Gitee 可以看到你刚才上传的项目。

邀请其他人协作
你建好仓库后,就可以邀请其他伙伴一起和你进行编码。
首先点击仓库名称,进入仓库。

点击管理,邀请小伙伴。


小伙伴加入后,就可以进入仓库,克隆该代码。

然后在 Pycharm 中打开。


或者是在欢迎界面选择 Get from VCS
。


等代码下载完成,如果你是仓库的成员,就可以进行代码的 commit、pull、push、update 等 Git 相关的操作了。
