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

如何同时提交到多个存储库,并根据每个存储库设置使用单独的提交用户名

  •  
  •   laters · 15 天前 · 1303 次点击

    Windows git https 方式如何实现同时推送到多个仓库,并根据每个仓库设置一个单独的提交用户名

    [remote "github"]
        url = https://github.com/jock/test
        fetch = +refs/heads/*:refs/remotes/origin/*
    	
    [remote "gitlab"]
        url = https://gitlab.com/test
        fetch = +refs/heads/*:refs/remotes/origin/*|
    

    我如何能为 github gitlab 分别设置对应的提交用户名

    github:github-username
    
    gitlab: gilab-username
    
    17 条回复    2024-09-06 09:18:28 +08:00
    857681664
        1
    857681664  
       14 天前
    git 应该没有这种操作吧,或者你写个脚本叫 switchgituser ,提交前执行一下,可以再结合一个自定义 shell 函数,gpushlab 的时候 switch 到 gitlab 的用户名
    momocraft
        2
    momocraft  
       14 天前
    什么是“提交用户名”
    lisongeee
        3
    lisongeee  
       14 天前
    你只是在本地使用当前用户邮箱生成了一个 commit ,然后把这个 commit 分别 push 到 两个远程仓库

    github/gitee 只是根据当前 commit 的 username 和 email 来映射到对应的平台用户

    解决方法是 github/gitee 使用同一个用户名和邮箱
    ETiV
        4
    ETiV  
       14 天前 via iPhone
    如果你了解 URL scheme 的话就会知道

    协议://(用户名:密码 @)域名/路径

    这种写法是通用的,在哪儿用都好使
    vvhy
        5
    vvhy  
       14 天前 via Android
    可以试试 includeIf: https://v2ex.com/t/1057899
    我没验证过
    msg7086
        6
    msg7086  
       14 天前
    author name 和 committer name 都是 commit 的一部分。你要设置的只能是推送用户名。
    body007
        7
    body007  
       14 天前
    https://man.openbsd.org/ssh_config

    试试在:~/.ssh/config 添加下面配置看看

    Host github.com
    User github-username

    Host gitlab.com
    User gilab-username
    laters
        8
    laters  
    OP
       14 天前
    就是我有一套代码,在 github 和 gitlab 上同时存了,我希望提交代码的时候,能一次性提交两个仓库,而提交时候的 username ,github 的仓库显示 A gitlab 仓库显示 B
    laters
        9
    laters  
    OP
       14 天前
    @msg7086 对的,这个能根据仓库 url 自动对应吗 ?
    laters
        10
    laters  
    OP
       14 天前
    @momocraft 仓库显示提交人的名字
    laters
        11
    laters  
    OP
       14 天前
    @body007 windows + https 的方式有办法实现吗
    sagaxu
        12
    sagaxu  
       14 天前
    https 的用户名可以写在 URL 中,这是 rfc 规定的格式

    https://[email protected]/jock/test.git
    https://[email protected]/jock/test.git

    git 一般通过 ssh 的 key 来配置,在~/.ssh/config 中为不同的域名配置不同的证书或 Key
    kinfuy
        13
    kinfuy  
       14 天前
    https://github.com/kinfuy/gacm 这个工具不仅仅可以管理 git 账户 还能处理 npm 镜像源
    davin
        14
    davin  
       14 天前
    手动创建 bat 或者 bash 文件,把命令塞进去?我能想到的直接方案
    griffinx
        15
    griffinx  
       14 天前
    理论上你的所有操作都只会在一个仓库,另外的都是同步而已。

    搞一个 pipeline 专门做这种事情,就像 golang 的 pr 合并之后会自动同步到 github 一样,不要在 local 搞
    relsoul
        16
    relsoul  
       14 天前
    sourcetree 可以设置不同仓库的每个仓库单独的 git name & git email
    ryanlid
        17
    ryanlid  
       13 天前
    对每个仓库单独设置就可以了

    git config --local user.name aaa
    git config --local user.email [email protected]
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2391 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 15:56 · PVG 23:56 · LAX 08:56 · JFK 11:56
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.