【git】修改git凭据

Windows

poweshell 复制代码
# 删除 Windows 凭据
cmdkey /delete:git:https://github.com

# 删除本地 git 配置
git config --global --unset user.name
git config --global --unset user.email

# 设置新的 git 配置(请修改为你的信息)
git config --global user.name "你的新用户名"
git config --global user.email "你的新邮箱"

# 清除 git 缓存的凭据
git config --global --unset credential.helper

# 提示完成
Write-Host "Git 配置已重置,下次push时需要重新输入 GitHub 账号密码" -ForegroundColor Green

Linux

bash 复制代码
#!/bin/bash

# 删除缓存的凭据
git config --global --unset credential.helper
rm -rf ~/.git-credentials

# 清除 SSH 密钥(可选,取消注释如果需要)
# rm -rf ~/.ssh/id_rsa*

# 删除全局 git 配置
git config --global --unset user.name
git config --global --unset user.email

# 设置新的 git 配置
echo "请输入你的 Git 用户名:"
read username
echo "请输入你的 Git 邮箱:"
read email

git config --global user.name "$username"
git config --global user.email "$email"

# 清除本地凭据缓存
git config --global credential.helper cache
git config --global --unset credential.helper

echo -e "\033[32mGit 配置已重置,下次push时需要重新输入 GitHub 账号密码\033[0m"
相关推荐
云原生指北1 小时前
Docker Sandboxes 工作区怎么接:Direct、Clone 和它们的边界
git·docker·agent
菠萝猫yena2 小时前
【git】git 命令常用组合
大数据·git·elasticsearch
Liekkas Kono5 小时前
aicommits 工具接入 Codex CLI 使用
git·swhl·aicommits
KieranYin6 小时前
Git | WorkTree(工作树)
git
ly76898 小时前
Git 从入门到实战:原理、工作流、分支管理、撤销恢复与团队协作
git·源代码管理
JavaDog程序狗9 小时前
【规范】这套 Git 规范,救了整个团队
git·代码规范·workflow
喜乐MI9 小时前
Git 分支操作避坑指南:merge、cherry-pick、revert 与 reset 怎么选?
git·github
fpcc1 天前
工具使用—git add命令分析说明
git·工具
独隅1 天前
VS Code Git 工作树多分支并行开发实战指南
大数据·git·elasticsearch
丑过三八线1 天前
Git 合并未合并分支完整教程
git