【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"
相关推荐
2401_891655811 小时前
Git + 云原生:如何管理K8s配置版本?
git·云原生·kubernetes
m0_528174452 小时前
Git对象存储原理(blob/tree/commit) 引用日志(reflog)
大数据·git·elasticsearch·全文检索
无限进步_2 小时前
【C++】单词反转算法详解:原地操作与边界处理
java·开发语言·c++·git·算法·github·visual studio
Wzx1980125 小时前
Git分布式版本控制工具
git
whale fall17 小时前
git add、git commit、git push 的区别和联系
git
倾云鹤17 小时前
Git同时推送多个远程仓库
git
sdm07042721 小时前
基础开发工具git,gdb
git
胡琦博客1 天前
如何同步远程分支到本地(远程有些分支已经删除了)
git
AI成长日志1 天前
【实用工具教程】Git进阶:分支策略与合并冲突解决
git
ruanCat1 天前
加了 .gitattributes 就万事大吉?我差点毁了整个团队的 Git 工作流
git