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

github 公司和个人帐号分离

  •  
  •   wellhome · 2021-03-27 19:10:46 +08:00 · 5114 次点击
    这是一个创建于 1097 天前的主题,其中的信息可能已经有所发展或是发生改变。
    有好的解决方案吗?
    terminal 端需要在 ssh 下配置两个不同的主机。
    web gui 又没有好的切换帐号的软件。
    20 条回复    2021-03-28 08:30:44 +08:00
    Dvel
        1
    Dvel  
       2021-03-27 19:30:19 +08:00
    Web 上可以用 Firefox 的 Multi-Account Containers
    dzdh
        2
    dzdh  
       2021-03-27 19:31:19 +08:00
    一个 ff 一个 chrome 表示没啥问题 :doge:
    ayase252
        3
    ayase252  
       2021-03-27 19:37:38 +08:00   ❤️ 3
    redtea
        4
    redtea  
       2021-03-27 19:38:26 +08:00   ❤️ 2
    弄两台电脑,否则迟早出事。
    Takamine
        5
    Takamine  
       2021-03-27 19:44:29 +08:00 via Android
    这个我是在.config 文件里面设置了不同的路由,但是认证信息发现还是有问题。
    ……只能每次二次确认。
    wbd31
        6
    wbd31  
       2021-03-27 20:07:03 +08:00
    我是用 ed25519 和 rsa 算法生成了两个 key 在 ~/.ssh 下。
    这样可以分别工作,虽然没理解原理。
    vision1900
        7
    vision1900  
       2021-03-27 20:12:18 +08:00
    VM 或者 WSL
    BeautifulSoap
        8
    BeautifulSoap  
       2021-03-27 20:13:42 +08:00
    等等,lz 的 github 到底指的是 git 不同账号,还是浏览器里 github 登陆不同账号?

    浏览器 github 账号的话就用 firefox,firefox 的 container 是真的非常好用,firefox 的几个优势功能之一

    git 的的话不想纠结配置只想点鼠标的话,可以使用 fork 这个 git 的 gui,能轻松在几个账号间切换
    renmu123
        9
    renmu123  
       2021-03-27 20:37:06 +08:00 via Android
    终端设置好 ssh.config 就可以了,浏览器的话可以开两个不同的分别登录
    DogBear
        10
    DogBear  
       2021-03-27 20:44:24 +08:00 via Android   ❤️ 1
    ${HOME}/.ssh/config 指定不同 host 以及对应身份和私钥
    web 端用两个浏览器分别登录不同账号
    liuzhaowei55
        11
    liuzhaowei55  
       2021-03-27 20:49:07 +08:00
    公司的用 SSH,个人的使用 HTTP 方式就可以了。
    SjwNo1
        12
    SjwNo1  
       2021-03-27 21:04:25 +08:00
    `ssh-add -k your_rsa_path`
    xingheng
        13
    xingheng  
       2021-03-27 21:41:22 +08:00
    Host github github.com
    HostName github.com
    User git
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/github
    IdentitiesOnly yes


    Host github-guest github.com
    HostName github.com
    User git
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/github-guest
    IdentitiesOnly yes
    ClericPy
        14
    ClericPy  
       2021-03-27 22:38:02 +08:00
    ssh 的 config 文件不好吗, 我好几个电脑的不同系统共用一套 config, 虽然过几天公司要改成统一用跳板机不知道对 git 有没有影响

    暂时是不同公司不同文件夹, 反正顶层 Include ~/.ssh/company1/config 一堆子文件夹下的 config+.pub 还是挺好用的, 相对路径还是香
    quxiangxuanqxx
        15
    quxiangxuanqxx  
       2021-03-27 23:06:05 +08:00
    每个项目都可以单独设置 .git config 你的需求完全可以实现,项目的 config 优先级高于全局。

    但是,我还是建议自己私人项目不要使用公司财产(如果电脑是公司发的),上班时间使用公司财产的代码产出所属权归公司。
    dvaknheo
        16
    dvaknheo  
       2021-03-27 23:17:48 +08:00
    用 pageant 那个小东西管理 不同的密钥?
    jiangzm
        17
    jiangzm  
       2021-03-27 23:52:15 +08:00
    同一个 git 服务为什么要分开?
    如果你公司用的是 github 企业版那就是两个不同的 git 服务,可以用~/.ssh/config 区分不同 host 使用不同的 pub_key 。
    如果你公司用的也是社区版,那就把公司邮箱加到你个人账户的 emails 里面就好了,然后本地默认配置个人邮箱或者公司邮箱,但是非默认配置邮箱的项目需要设置下项目级别的 email 和 username 就好了(或者用 includeIf 区分目录动态配置)。

    如果已经有两个 github 账户对应个人和公司的项目,那就其中一个账户的 github 地址用别名好了。
    比如~/.ssh/config 配置为:
    ```
    Host github.com
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa_github1
    User gituser1

    Host github2.com
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa_github2
    User gituser2
    ```
    使用的唯一差别就是下载代码的时候记得把公司项目的 ssh 地址 github.com 改成 github2.com (或者其他别名)

    另外使用 includeIf 区分不同目录使用不同.gitconfig,需要本地 git 版本是 2.13.0 以上才支持
    在~/目录下面存在三个配置文件,
    .gitconfig // 全局通用配置文件
    .gitconfig-my // 个人工程配置文件
    .gitconfig-work // 公司工程配置文件

    全局~/.gitconfig 配置如下
    ```
    [user]
    name = yourname
    email = [email protected]
    [includeIf "gitdir:~/myspace/"]
    path = .gitconfig-my
    [includeIf "gitdir:~/workspace/"]
    path = .gitconfig-work
    ```
    个人.gitconfig-my 配置如下
    ```
    [user]
    name = gituser1
    email = [email protected]
    ```
    公司.gitconfig-work 配置如下
    ```
    [user]
    name = gituser2
    email = [email protected]
    ```
    ETiV
        18
    ETiV  
       2021-03-28 05:50:10 +08:00
    为啥非要走 ssh 协议,https+token 也是可以的
    SenLief
        19
    SenLief  
       2021-03-28 08:25:26 +08:00
    上班的时候为什么要用个人的,上班时间产出都算作公司的。
    wellhome
        20
    wellhome  
    OP
       2021-03-28 08:30:44 +08:00 via iPhone
    我统一回复一下。我有一些个人技巧,仅自己看。是放在自己的 repo 里。不是编码。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3378 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 13:15 · PVG 21:15 · LAX 06:15 · JFK 09:15
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.