Skip to main content

One Laptop, Five Clients: Separate Git Identities & SSH Keys

Learn how to manage multiple freelance clients on a single machine using Git's includeIf feature and separate SSH keys per folder.

AI-written
Inewgen
Live18 Oct 2026Source: Dev.to3 min read (0 views)
Share
One Laptop, Five Clients: Separate Git Identities & SSH Keys

Stock photo for illustration only, not from the actual event

Font size
  • Use Git's includeIf feature to automatically switch email and identity based on your current working directory.
  • Generate dedicated SSH keys for each client to prevent authentication errors with platforms like GitHub or GitLab.
  • Securely manage environment variables and .env files using tools like direnv.
  • Configure global ignore files and pre-commit hooks to prevent accidental API key leaks.

Freelancing for multiple clients simultaneously quickly turns Git into a messy affair. Different clients require distinct credentials, such as agency email addresses, separate GitHub organization accounts, or GitLab repositories, all while keeping your personal projects distinct. A minor slip-up, like committing with the wrong email address or hitting a Permission denied public key error, looks sloppy and wastes valuable time.

To solve this, developer Abid Ali recommends a streamlined setup for handling multiple clients from a single machine, taking about twenty minutes to configure. Everything relies on a predictable, well-structured directory layout where work folders are neatly separated by client names.

directory folder tree workspace computer screen

Stock photo for illustration only, not from the actual event

Git can apply specific configurations based on where a repository lives on disk using the includeIf "gitdir:..." directive, while SSH can select keys based on host aliases. Combined together, your current working folder automatically determines your active identity.

Your global configuration file holds your default settings alongside individual include paths for each client. For example:

Never miss the latest news?

Subscribe to get news summaries by email - not often enough to be annoying.

โฆษณา

  • Defining your default [user] credentials for personal use.
  • Adding [includeIf] blocks pointing to client-specific configuration files.
  • Verifying the configuration inside client repositories using git config user.email and checking origins with --show-origin.

Utilizing the includeIf feature and client-specific SSH keys serves as an essential security best practice for freelancers and developers switching between multiple environments. It ensures that sensitive credentials and access tokens from one client project never bleed into another.

When handling authentication, if a client provides a separate GitHub account, you must generate a dedicated SSH key using ssh-keygen -t ed25519, assign a passphrase, and add the corresponding public key to that specific account.

There are two primary ways to ensure Git selects the appropriate key: configuring core.sshCommand within the client include block, or setting up host aliases in ~/.ssh/config. Beyond identity management, handling environment variables securely with tools like direnv and employing pre-commit hooks to scan for sensitive API keys before pushing code completes a robust developer workflow.

Source: Dev.to

Comments

Leave a Comment
0/2000

Found something wrong in this article? Report an issue with this article