• 请不要在回答技术问题时复制粘贴 AI 生成的内容
404www
V2EX  ›  程序员

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

  •  
  •   404www · Aug 22, 2024 · 3187 views
    This topic created in 805 days ago, the information mentioned may be changed or developed.

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

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

    GIT_SSH_COMMAND="ssh -i ~/.ssh/xxxxx-1" git push origin main
    coolcoffee
    coolcoffee
    Aug 22, 2024❤️1
    4
    生成两个私钥是必须的,我是通过 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
    shuzijumin
    Aug 22, 2024❤️1
    5
    https://shuzijumin.com/thread-989-1-2.html 我自己是这样管理多账号,很方便
    ashin
    ashin
    Aug 23, 2024 via iPhone
    6
    panda1001
    panda1001
    Aug 23, 2024
    7
    在 CI 脚本看到的,两个账号分别申请 token 管理
    GH_TOKEN=$(cat $GH_TOKEN_PATH)
    git push "https://[email protected]/$GH_USER/$GH_REPO.git" master:master
    Hopetree
    Hopetree
    Aug 23, 2024
    9
    看看这个项目 https://github.com/gauseen/gum 可以管理多个 git 账号,本地切换,直接一个命令就能切,之前我用过,还可以,你看看是不是满足你的场景
    ic3z
    ic3z
    Aug 23, 2024 via iPhone
    12
    不同的 github 加不同的 remote origin
    404www
    404www
    OP
    Aug 23, 2024
    13
    @coolcoffee 谢谢大佬,我试试
    404www
    404www
    OP
    Aug 23, 2024
    14
    谢谢上面出主意的各位大佬
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1362 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 46ms · UTC 19:00 · PVG 03:00 · LAX 11:00 · JFK 14:00
    ♥ Do have faith in what you're doing.