V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
404www
V2EX  ›  程序员

请教两个 github 账号怎么分别管理

  •  
  •   404www · 25 天前 · 1388 次点击

    我有两个 github 账号,在本地修改不同账号的项目时,怎么用不同的账号推送到对应 github ,可以生成两个私钥然后每次选择哪个吗

    14 条回复    2024-08-23 22:02:04 +08:00
    luckyscript
        1
    luckyscript  
       25 天前
    可以搞两个文件夹,分别放这俩账号的项目。git config 可以根据不同的目录来配置不同的账号。
    llxvs
        2
    llxvs  
       25 天前 via iPhone   ❤️ 1
    可以,用 git config —local core.sshcommand 设置用哪个私钥,只对当前库有效
    hlwjia
        3
    hlwjia  
       25 天前   ❤️ 1
    我都是这样 🤣

    GIT_SSH_COMMAND="ssh -i ~/.ssh/xxxxx-1" git push origin main
    coolcoffee
        4
    coolcoffee  
       25 天前   ❤️ 1
    生成两个私钥是必须的,我是通过 sshconfig 里面的 host alias 来区分的。

    ```
    Host github.com
    IdentityFile ~/.ssh/id_rsa

    Host github-company
    HostName github.com
    IdentityFile ~/.ssh/company-github.pub
    ```

    以 jquery 的仓库举例,假如我直接用 GitHub 上面提供的 ssh 地址 [email protected]:jquery/jquery.git ,就会走到第一个;

    如果我手动改成 git@github-company:jquery/jquery.git , 根据 ssh alias 就会使用另外一个密钥。
    shuzijumin
        5
    shuzijumin  
       25 天前
    https://shuzijumin.com/thread-989-1-2.html 我自己是这样管理多账号,很方便
    ashin
        6
    ashin  
       25 天前 via iPhone
    panda1001
        7
    panda1001  
       24 天前
    在 CI 脚本看到的,两个账号分别申请 token 管理
    GH_TOKEN=$(cat $GH_TOKEN_PATH)
    git push "https://[email protected]/$GH_USER/$GH_REPO.git" master:master
    v23xowen
        8
    v23xowen  
       24 天前
    Hopetree
        9
    Hopetree  
       24 天前
    看看这个项目 https://github.com/gauseen/gum 可以管理多个 git 账号,本地切换,直接一个命令就能切,之前我用过,还可以,你看看是不是满足你的场景
    hi909
        10
    hi909  
       24 天前 via iPhone
    nekomiya
        11
    nekomiya  
       24 天前 via Android
    ic3z
        12
    ic3z  
       24 天前 via iPhone
    不同的 github 加不同的 remote origin
    404www
        13
    404www  
    OP
       24 天前
    @coolcoffee 谢谢大佬,我试试
    404www
        14
    404www  
    OP
       24 天前
    谢谢上面出主意的各位大佬
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   875 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 20:28 · PVG 04:28 · LAX 13:28 · JFK 16:28
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.