glab Authentication with Multiple GitLab Instances
When using glab (the GitLab CLI) with multiple GitLab instances - such as gitlab.com for personal projects and a self-hosted GitLab for work - authentication can become problematic if you’re using the GITLAB_TOKEN environment variable. The Problem glab supports per-host token configuration in its config file (~/.config/glab-cli/config.yml). Each host can have its own token: hosts: gitlab.com: token: glpat-xxxxx gitlab.sehlat.io: token: glpat-yyyyy However, if you set the GITLAB_TOKEN environment variable (commonly done in shell rc files), it overrides all per-host tokens. This means the same token gets used for every GitLab instance, causing 401 Unauthorized errors on instances where that token isn’t valid. ...