编辑
2024-11-05
技术杂谈
00
请注意,本文编写于 114 天前,最后修改于 2 天前,其中某些信息可能已经过时。

Git 的常见工作流程

1. 单人工作流:

  1. 初始化仓库:git init
  2. 修改文件。
  3. 添加到暂存区:git add <文件>
  4. 提交到本地库:git commit -m "描述"
  5. 如果有远程库,推送到远程:git push origin master

2. 团队协作工作流:

  1. 克隆远程仓库:git clone
  2. 创建分支:git branch feature
  3. 切换分支:git checkout feature
  4. 修改文件、提交更改:git commit -m "描述"
  5. 合并到主分支,解决冲突:git merge
  6. 推送到远程库:git push

更改密码后 如果您需要更改密码,请先清除存储的旧密码:

shell
git credential reject

避免 pull 时需要多次输入账号信息 配置全局 credential.helperstore

shell
git config --global credential.helper store

【或者】在 .gitconfigconfig 文件中确认以下内容已写入:

text
[credential] helper = store

处理 VPN 代理问题 如果使用 VPN 导致访问异常,可尝试以下操作诊断并修复:

刷新 DNS 缓存

shell
ipconfig /flushdns

查看当前代理配置

shell
git config --global http.proxy git config --global https.proxy

设置 HTTP 和 HTTPS 代理 根据 VPN 工具的端口配置代理:

HTTP 代理(如 Clash 的默认端口 7890):

shell
git config --global http.proxy http://127.0.0.1:<端口号> git config --global https.proxy https://127.0.0.1:<端口号>

SOCKS5 代理:

shell
git config --global http.proxy socks5://127.0.0.1:2333 git config --global https.proxy socks5://127.0.0.1:2333

取消代理设置 如果不再需要代理,可取消配置:

shell
git config --global --unset http.proxy git config --global --unset https.proxy

本文作者:Freed

本文链接:

版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!