【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"
相关推荐
先跑起来再说6 小时前
Git 入门到实战:一篇搞懂安装、命令、远程仓库与 IDEA 集成
ide·git·后端·elasticsearch·golang·intellij-idea
承渊政道9 小时前
Linux系统学习【Linux系统的进度条实现、版本控制器git和调试器gdb介绍】
linux·开发语言·笔记·git·学习·gitee
Doro再努力9 小时前
【Linux操作系统12】Git版本控制与GDB调试:从入门到实践
linux·运维·服务器·git·vim
摇滚侠11 小时前
MAC IDEA GIT 提交区显示了几个不存在的目录
git·idea
城东12 小时前
Git使用[远程仓库远端的head比本地和提交的head旧,其他人拉不到最新代码]
git·head·远程仓库远端·比本地和提交的head旧·其他人拉不到最新代码
何中应21 小时前
使用SSH地址拉取远程仓库代码报下面的错误
git
何中应21 小时前
Git本地仓库命令补充
git
sun0077001 天前
执行repo sync -c -d -j4以后,提交未git push的代码看不到了。要怎么恢复?
git
胖虎11 天前
Git 一个本地仓库同时推送到两个远程仓库(详细教程)
git·多远程仓库·双远程仓库·git双远程·git备份
春日见2 天前
如何创建一个PR
运维·开发语言·windows·git·docker·容器