Git 配置实践
Git 配置实践
目录
-
Git 仓库配置与使用
- 在 PyCharm 中配置 Git
- VSCode 中的 Git 操作
Git 仓库配置与使用
在开发中,Git 是不可或缺的版本管理工具。对于 PyCharm 或 VSCode 用户,熟悉 Git 配置和仓库管理可以提升效率。
1. 检查 Git 安装
git --version
输出示例:
git version 2.25.1
2. 配置全局用户名和邮箱
git config --global user.name "Your Name"
git config --global user.email "youremail@example.com"
3. 在 PyCharm 中使用 Git
-
打开 PyCharm → Settings → Version Control → Git
-
指定 Git 可执行文件路径(如
/usr/bin/git) -
测试连接成功后,可以直接在 PyCharm 内进行:
- 提交 (Commit)
- 推送 (Push)
- 拉取 (Pull)
4. 在 VSCode 中使用 Git
-
安装 Git 插件(通常默认自带)
-
打开仓库文件夹,VSCode 会自动识别 Git
-
可以直接在 Source Control 面板:
- 查看变更
- 提交
- 推送到远程仓库
5. 常用命令
# 初始化仓库
git init# 克隆远程仓库
git clone https://github.com/user/repo.git# 查看状态
git status# 添加变更
git add .# 提交
git commit -m "Initial commit"# 推送
git push origin main
