惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

罗磊的独立博客
SecWiki News
SecWiki News
酷 壳 – CoolShell
酷 壳 – CoolShell
爱范儿
爱范儿
量子位
M
MIT News - Artificial intelligence
GbyAI
GbyAI
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
TaoSecurity Blog
TaoSecurity Blog
博客园 - 【当耐特】
H
Heimdal Security Blog
腾讯CDC
The Last Watchdog
The Last Watchdog
Security Archives - TechRepublic
Security Archives - TechRepublic
Hacker News: Ask HN
Hacker News: Ask HN
S
Schneier on Security
Microsoft Security Blog
Microsoft Security Blog
WordPress大学
WordPress大学
博客园 - 司徒正美
Recent Commits to openclaw:main
Recent Commits to openclaw:main
C
Cybersecurity and Infrastructure Security Agency CISA
S
SegmentFault 最新的问题
大猫的无限游戏
大猫的无限游戏
Application and Cybersecurity Blog
Application and Cybersecurity Blog
F
Full Disclosure
有赞技术团队
有赞技术团队
T
Tailwind CSS Blog
Engineering at Meta
Engineering at Meta
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
T
Threatpost
月光博客
月光博客
A
Arctic Wolf
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
雷峰网
雷峰网
T
Troy Hunt's Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The Cloudflare Blog
D
DataBreaches.Net
O
OpenAI News
L
LINUX DO - 最新话题
宝玉的分享
宝玉的分享
小众软件
小众软件
V
Vulnerabilities – Threatpost
A
About on SuperTechFans
人人都是产品经理
人人都是产品经理
T
The Exploit Database - CXSecurity.com
Martin Fowler
Martin Fowler
美团技术团队
P
Privacy International News Feed

Linux – 网上冲浪指南

手动升级一下 OpenWRT 如何安全地面向公网提供本地 NAS 上的 Web 服务 迁移博客到 VPS 解决 Qsirch 无法搜索文件夹的问题 N100 小主机遭遇 NVMe 硬盘故障:一次系统的诊断与反思 外接显示器 EDID 损坏如何处理 How to simulate hard disconnection for websocket 似乎修复了唤醒后键盘短暂失效的问题 性能与公平:解决 Linux 桌面无响应的取舍之道
How to switch GitHub CLI account automatically
Zeeko · 2025-11-17 · via Linux – 网上冲浪指南

Working with multiple GitHub accounts on the same machine can be tricky, but we can automate account switching when changing workspaces. Here’s my solution using Fish Shell and Direnv.

Prerequisites

Install direnv, this handy tool automatically loads environment variables when you cd into directories.

The Setup

Add this function to your Fish Shell configuration:

function __gh_auth_switch_gh_account --on-variable GH_ACCOUNT
  if test -n "$GH_ACCOUNT"
    gh auth switch --user "$GH_ACCOUNT"
  end
end

How it works

Let’s break down the snippet:

  1. --on-variable tells Fish Shell to run this function when the variable GH_ACCOUNT changes value.
  2. test -n $GH_ACCOUNT returns true if the length of GH_ACCOUNT is non-zero.
  3. gh auth switch --user "$GH_ACCOUNT" switches the active account to $GH_ACCOUNT.

For example, if we need to switch to gh-user-1 under path/to/company/ . We can add a .envrc file under path/to/company

export GH_ACCOUNT=gh-user-1

When we cd into path/to/company/project1, direnv will set the GH_ACCOUNT variable automatically, and the callback function __gh_auth_switch_gh_account will be invoked by the Fish Shell to make gh-user-1 active.