V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
git
Pro Git
Atlassian Git Tutorial
Pro Git 简体中文翻译
GitX
xiaoyanbot
V2EX  ›  git

Git for Windows 记住了一个 github 的账户密码,切换另外一个账号,找不到切换的方式

  •  
  •   xiaoyanbot · 2017-05-20 15:09:09 +08:00 · 5548 次点击
    这是一个创建于 2526 天前的主题,其中的信息可能已经有所发展或是发生改变。
    git push -u origin master
    remote: Permission to */*.git denied to JiaFeiX.
    fatal: unable to access 'https://github.com/*/*.git/': The requested URL returned error: 403
    

    http://www.cnblogs.com/jarvisjin/p/5915419.html 这篇教程说,有个 .git-credentials 文件保存, 但用 Everything 搜索遍了文件,都没有这个

    是不是新版的 git for windows 保存密码的方式改变了? 具体保存在哪里呢? 怎么改变呢?

    只要忘记密码就可以了。

    git for windows 的版本为: 2.11

    12 条回复    2017-05-21 07:43:52 +08:00
    xiaoyanbot
        1
    xiaoyanbot  
    OP
       2017-05-20 15:13:15 +08:00
    git
    forcecharlie
        2
    forcecharlie  
       2017-05-20 15:41:06 +08:00 via iPhone
    windows 凭据管理器里面删除
    woshixiaohao1982
        3
    woshixiaohao1982  
       2017-05-20 16:11:42 +08:00
    讲实在话,git 这类出身就是为 Unix 命令行环境编写的工具 建议不要在 windows 下使用,真心的,,这种问题,,在 Unix 下面就是两行脚本就能搞定的事情,
    woshixiaohao1982
        4
    woshixiaohao1982  
       2017-05-20 16:14:29 +08:00
    命令行 windows 下是没有环境变量的, 像 Unix ~代表的就是用户默认目录,绝大部分配置文件 都是以.开头 配置在这个目录下面,windows 下除了安装 zsh-terminal 可以模拟一下,个人实在不建议使用 Windows 作为开发,除非你真的需要 Net 等环境除外
    ifishman
        5
    ifishman  
       2017-05-20 18:25:22 +08:00 via Android
    所以我项目添加远程仓库的时候就直接在链接里面做好 http 认证,反正只有我一个人能打开电脑
    atempcode
        6
    atempcode  
       2017-05-20 18:45:15 +08:00
    为什么用 https 呢,为什么不用 public key 呢?
    phrack
        7
    phrack  
       2017-05-20 19:13:58 +08:00 via Android
    试试 gitbash,比 git 客户端应该好用很多~
    nannanziyu
        8
    nannanziyu  
       2017-05-20 19:24:25 +08:00   ❤️ 1
    我来详细解释一下吧
    windows git 的 config 目录通常有两个位置
    1,[Git InstallDir]\mingw32\etc\gitconfig
    2,%home%\.gitconfig
    其中[Git InstallDir]就是 git 安装目录,%home%是环境变量,如果环境变量没有 home,那么就取默认的 C:\Users\[Username]\
    另外的,如果在一个 repo 目录下,那么[Repo Dir]\.git\config 也是生效的。

    有一行简单的命令能够输出所有配置项以及配置项的位置:
    git config --list --show-origin

    -----------------------------------------------------------------------------------------
    简单的来说在使用 http 方式的情况下,如果 git config --global credential.helper = store,那么输入用户名和密码后,会在%home%\.git-credentials 保存
    对于楼主的情况,可以把%home%\.git-credentials 删掉,也可以把[Repo Dir]\.git\config 中的 remote.origin.url 改成 https://[new_username]@github.com/*/*.git/
    forcecharlie
        9
    forcecharlie  
       2017-05-20 19:34:33 +08:00   ❤️ 2
    @nannanziyu
    @xiaoyanbot

    Git for Windows 的密码存储使用的是 https://github.com/Microsoft/Git-Credential-Manager-for-Windows/,而 Git-Credential-Manager-for-Windows 使用的是 Windows 凭据管理的功能,如果按照你的设置,改变默认的 Git-Credential-Manager-for-Windows 作为管理密码的机制,则可能出现明文存储密码的安全风险。

    要删除存储的密码,可以去凭据管理器中删除对应网站的密码。

    控制版面管理路径为: 控制面板\用户帐户\凭据管理器

    https://github.com/Microsoft/Git-Credential-Manager-for-Windows/ 可以嵌入到所有 Windows 7 or Later 平台的 .Net Framework 程序做密码管理。
    ynyounuo
        10
    ynyounuo  
       2017-05-20 20:12:55 +08:00
    如果长期用多个帐号可以用多个 SSH keys 来管理帐号切换

    在 .ssh/config 设置可供区分的 Host 和公钥地址
    Host github-alt
    HostName github.com
    IdentityFile ~/.ssh/id_rsa_alt

    然后在需要更换正好的原项目目录下执行类似下面的内容,可以保存成可执行文件叫个啥 git-username 之类的
    git config user.name "name";
    git config user.email "[email protected]";
    sed -i '' 's/github.com/github-alt/g' .git/config

    当然你也可以在母文件夹写 gitconfig
    ynyounuo
        11
    ynyounuo  
       2017-05-20 20:13:52 +08:00
    *帐号 - -
    才发现是 Windows 啊 - - 不过思路类似
    beginor
        12
    beginor  
       2017-05-21 07:43:52 +08:00 via Android
    呵呵,其实 git 可以这样记录密码 https://beginor.github.io/2014/03/04/git-client-save-user-pass.html
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2668 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 05:12 · PVG 13:12 · LAX 22:12 · JFK 01:12
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.