【PyCharm】配置 Git 教程
之前给大家介绍了 Git 安装及使用指南,今天再给大家介绍一下在 PyCharm 中使用 Git。
1
打开 File -> Settings -> Version Control -> Git
,在 Path to Git executable
处选择 git 的安装位置。
![](https://upload-images.jianshu.io/upload_images/14733701-cc01159b5ef8c81d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
配置完成之后,点击【Test】按钮,如果成功,则会显示 Git 版本信息,如下图:
![](https://upload-images.jianshu.io/upload_images/14733701-80340610ea038f6b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
2
点击 VCS -> Checkout from Version Control -> Git
![](https://upload-images.jianshu.io/upload_images/14733701-225db986782758a4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
输入 GitHub 仓库的地址和本地目录,需要注意的是:这个目录必须是空的,不能有任何文件。PyCharm 新建项目的时候,会自动创建 .idea
文件夹,这个也不能有,必须删掉。
![](https://upload-images.jianshu.io/upload_images/14733701-00c4c67cb06bbd83.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
点击【Log in to GitHub】,输入用户名密码登录:
![](https://upload-images.jianshu.io/upload_images/14733701-10d8da93aa47993c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
登录成功以后,点击【Clone】。Git 克隆完成。
3
在项目中新建文件,弹出提示框:是否将文件添加到 Git。
![](https://upload-images.jianshu.io/upload_images/14733701-ae213f0fa4d8c6e6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
这里可以勾上 Remember, don't ask again
在点击【Yes】,这样就不会每次新建文件都弹出来了。
打开 右键 -> Git -> Commit File...
,输入 Commit Message
后点击下方【Commit】按钮。注意,提交日志是必须填的,否则不给提交的。
![](https://upload-images.jianshu.io/upload_images/14733701-b4a68a1102744b1f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/14733701-cc6c7e34371a7aaf.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
已经提交的文件文件名显示是 白色,未提交的文件文件名显示是 绿色,如下图:
![](https://upload-images.jianshu.io/upload_images/14733701-8d7bb3782fb1762f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
打开 右键 -> Git -> Repository -> Push
,点击【Push】按钮,将代码提交到 GitHub。
![](https://upload-images.jianshu.io/upload_images/14733701-74af4ef3819e8004.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)