爱意满满的作品展示区。
kinfuy

git 账户管理工具

  •  1
     
  •   kinfuy · Mar 8, 2024 · 3302 views
    This topic created in 979 days ago, the information mentioned may be changed or developed.

    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 replies  •  2024-03-08 16:51:16 +08:00
    passive
    passive
    Mar 8, 2024 via Android❤️4
    1
    git 自带的

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

    不行吗
    jiang24gdufs
    jiang24gdufs
    Mar 8, 2024❤️1
    2
    谢谢分享
    Sezxy
    Sezxy
    Mar 8, 2024
    3
    zthxxx
    zthxxx
    Mar 8, 2024
    4
    这个需求直接用 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
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2120 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 14:51 · PVG 22:51 · LAX 06:51 · JFK 09:51
    ♥ Do have faith in what you're doing.