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

git 账户管理工具

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

    腾讯云最新优惠活动来了:云产品限时1折,云服务器低至88元/年 ,点击这里立即抢购:9i0i.cn/qcloud,更有2860元代金券免费领取,付款直接抵现金用,点击这里立即领取:9i0i.cn/qcloudquan

    (福利推荐:你还在原价购买阿里云服务器?现在阿里云0.8折限时抢购活动来啦!4核8G企业云服务器仅2998元/3年,立即抢购>>>:9i0i.cn/aliyun


    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  
       65 天前 via Android   ?? 4
    git 自带的

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

    不行吗
    jiang24gdufs
        2
    jiang24gdufs  
       65 天前   ?? 1
    谢谢分享
    Goooooos
        3
    Goooooos  
       65 天前
    zthxxx
        4
    zthxxx  
       65 天前
    这个需求直接用 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   ·   实用小工具   ·   4222 人在线   最高记录 6547   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 05:23 · PVG 13:23 · LAX 22:23 · JFK 01:23
    Developed with CodeLauncher
    ? Do have faith in what you're doing.


    http://www.vxiaotou.com