multiple accounts

[!TIP|label: Multiple Accounts]

TYPE
ACCOUNTS
EMAIL
SSH KEY
GITHUB REPOS RANGE

work

John Doe

john@work.com

~/.ssh/work_ed25519

git@github.com:work/*

service account

jenkins

jenkins@work.com

~/.ssh/jenkins_ed25519

git@github.com:company/*

personal

John Doe

john@personal.com

~/.ssh/personal_ed25519

git@github.com:john/*

  • ~/.gitconfig.d/accounts/<account> is used to distinguish accounts and emails

  • ~/.gitconfig.d/.gitconfig is used to distinguish the git remote URLs by includeIf hasconfig:remote.*.url

  • ~/.ssh/config.d/github is used to distinguish the ssh key by host-alias

[!NOTE]

  • to check git the git clone debug log via:

GIT_TRACE=true GIT_CURL_VERBOSE=true GIT_TRACE_PACK_ACCESS=true GIT_TRACE_SETUP=true GIT_TRACE_SHALLOW=true \
git clone <repo-url>

with ssh

gitconfig

ssh config

  • ~/.ssh/config.d/github

    [!TIP] the HOST name alias should matches to the URL in gitconfig

  • ~/.ssh/config

    [!TIP]

    • put the include in the beginning of the ~/.ssh/config file

with https

[!NOTE]

TOKEN TYPE

GIT OPERATIONS (clone/push)

GIT LFS UPLOAD/DOWNLOAD

GITHUB ACTIONS (WORKFLOW)

semantic-release

GITHUB API (REST/GRAPHQL)

PRIVATE SUBMODULES

GITHUB CLI (GH)

NOTES

Fine-grained PAT

βœ“

βœ— Fails (LFS lock verification denied)

βœ“

βœ“

βœ“

βœ—

⚠️ Partially supported

Secure and scoped, but limited in CLI/automation contexts like Git LFS

Classic PAT

βœ“

βœ“

βœ“

βœ“

βœ“

βœ“

βœ“

Recommended for CLI tools, LFS, CI/CD, automation, and broad API access

gitconfig

setup .git-credentials

git hook and alias

[!NOTE]

  • setup the ~/.git-template directory as the template directory for git

[!TIP] ~/.git-templates/set-git-user.sh will be using for both post-checkout hook and git alias

git hook

[!TIP]

  • the post-checkout hook will be triggered after a git checkout command. it will set the git user name and email based on the remote URL automatically

  • verify by:

git alias

Last updated

Was this helpful?