git 账户管理工具

64 天前
 kinfuy

theme: nico

起因

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

开始

用法

just like nvm

gacm ls 

gacm use xxx ---local

gacm use xxx ---global

gacm add --name xxx --email xxx

gacm delate user

功能需求

获取 cli 模板

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

核心思路

git config --xxx user.name xxxx
git config --xxx user.email xxxx

源码

1496 次点击
所在节点    分享创造
4 条回复
passive
63 天前
git 自带的

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

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

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

给个简单的配置命令就是

git config --global 'includeIf.hasconfig:remote.*.url:git@github.com: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

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1021834

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX