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

推荐订阅源

WordPress大学
WordPress大学
T
Threatpost
阮一峰的网络日志
阮一峰的网络日志
美团技术团队
F
Fortinet All Blogs
The GitHub Blog
The GitHub Blog
月光博客
月光博客
V
Visual Studio Blog
T
Tailwind CSS Blog
Stack Overflow Blog
Stack Overflow Blog
博客园 - 聂微东
Jina AI
Jina AI
J
Java Code Geeks
Martin Fowler
Martin Fowler
大猫的无限游戏
大猫的无限游戏
Recorded Future
Recorded Future
C
Check Point Blog
腾讯CDC
N
Netflix TechBlog - Medium
aimingoo的专栏
aimingoo的专栏
罗磊的独立博客
Hacker News: Ask HN
Hacker News: Ask HN
SecWiki News
SecWiki News
博客园 - Franky
Hacker News - Newest:
Hacker News - Newest: "LLM"
N
News | PayPal Newsroom
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Security @ Cisco Blogs
W
WeLiveSecurity
The Last Watchdog
The Last Watchdog
Cloudbric
Cloudbric
F
Full Disclosure
The Cloudflare Blog
Y
Y Combinator Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
S
Schneier on Security
Schneier on Security
Schneier on Security
Spread Privacy
Spread Privacy
L
LINUX DO - 热门话题
AI
AI
N
News and Events Feed by Topic
T
Tor Project blog
P
Palo Alto Networks Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
H
Hackread – Cybersecurity News, Data Breaches, AI and More
G
Google Developers Blog

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.