V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
kinfuy
V2EX  ›  分享创造

git 账户管理工具

  •  1
     
  •   kinfuy · 50 天前 · 1468 次点击
    这是一个创建于 50 天前的主题,其中的信息可能已经有所发展或是发生改变。

    theme: nico

    起因

    最近多个项目老是需要切换 git 账号,git 命令都输入烦了,就想能不能像 nvm ,或者 nrm 一样管理 git 账户,正好最近写了一个 node-cli 的模板,正好有用武之地,说干就干。

    开始

    动画.gif

    用法

    just like nvm

    gacm ls 
    
    gacm use xxx ---local
    
    gacm use xxx ---global
    
    gacm add --name xxx --email xxx
    
    gacm delate user
    

    功能需求

    • 切换 git 账户(包含当前项目,全局用户,系统用户)
    • 增加用户
    • 删除用户
    • 查看用户列表

    获取 cli 模板

    拉取一下我的模板工具template-node-cli

    • 内置了基于 typescript+rollup+gulp 的打包工具
    • 给出了一些简单模板

    核心思路

    • 通过 cli 执行 shell 命令
    git config --xxx user.name xxxx
    git config --xxx user.email xxxx
    

    源码

    4 条回复    2024-03-08 16:51:16 +08:00
    passive
        1
    passive  
       50 天前 via Android   ❤️ 4
    git 自带的

    [includeIf "gitdir:~/work/"]
    path = ~/work/.gitconfig
    [includeIf "gitdir:~/opensource/"]
    path = ~/opensource/.gitconfig

    不行吗
    jiang24gdufs
        2
    jiang24gdufs  
       50 天前   ❤️ 1
    谢谢分享
    Goooooos
        3
    Goooooos  
       50 天前
    zthxxx
        4
    zthxxx  
       50 天前
    这个需求直接用 git config 中自带的能力,includeIf (配合 gitdir 或 hasconfig) 直接自动切配置,并不需要手动切换

    包括账号和各种配置,比如两套 ssh-key

    给个简单的配置命令就是

    git config --global 'includeIf.hasconfig:remote.*.url:[email protected]:zthxxx/**.path' ~/.config/git/github
    mkdir -p ~/.config/git
    git config --file ~/.config/git/github user.name zthxxx
    git config --file ~/.config/git/github user.email zthxxx.me@gmail.com


    比如我自己用的就在 https://github.com/zthxxx/init-macOS-dev/blob/f14141a9e03/init-app-preference.sh#L43-L49
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   899 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 22:07 · PVG 06:07 · LAX 15:07 · JFK 18:07
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.