Skip to main content

Manage multiple GitHub accounts on a single machine

Project description

GitSwap

Manage Multiple GitHub Accounts on Mac

GitSwap is a Python-based CLI tool that simplifies the process of managing multiple GitHub accounts (for example, a personal and a work account) on one machine. It allows quick switching between multiple GitHub accounts by updating your Git config and SSH config as needed.


Features

  • Multiple Identity Profiles: Add multiple Git identity profiles, each with a name, email, and SSH key.
  • Global or Local Scope: Switch the Git identity globally (affecting all repositories) or locally for the current repository only.
  • SSH Key Management: Configure SSH host aliases for each account so the correct SSH key is used when pushing to GitHub.
  • Host Aliases for GitHub: Each account is given a distinct SSH host alias (e.g., github-work for your work account).
  • User-Friendly CLI Commands: Provides intuitive subcommands.

Installation

pip install gitswap

Usage

Add a new account

gitswap add work -n "Your Name" -e "your.email@company.com" -k "~/.ssh/id_ed25519_work"

This creates an SSH config alias github-work and stores the profile in ~/.GitSwap.yml.

List configured accounts

gitswap list

Output:

Configured identities:
 - personal: Your Name <your.personal@example.com> (SSH key: /Users/you/.ssh/id_ed25519_personal)
 - work: Your Name <your.email@company.com> (SSH key: /Users/you/.ssh/id_ed25519_work)

Switch global identity

gitswap use work --global

This sets your global user.name and user.email to the work profile.

Switch identity locally (per repo)

cd ~/projects/personal/MyProj
gitswap use personal -l

This only changes the Git config in the current repository's .git/config.

Remove an identity

gitswap remove work

This deletes the "work" entry from ~/.GitSwap.yml and removes the corresponding block from ~/.ssh/config.

How It Works

Git Identity

Git uses user.name and user.email settings to identify the author of commits. GitSwap updates these settings either globally or locally for one repository.

SSH Key Management

To handle multiple accounts on GitHub, SSH keys are used to authenticate as different users. GitSwap uses SSH host aliases, such as github-work or github-personal, to point to GitHub but with specific SSH keys.

For example, an entry in your SSH config might look like:

Host github-work
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_ed25519_work
    AddKeysToAgent yes
    UseKeychain yes

Using Host Aliases in Git

Once an alias is set, you need to use it in your Git remote URL for repositories of that account. For instance:

git clone git@github-work:YourWorkUsername/YourRepo.git

Or update an existing repo's origin URL:

git remote set-url origin git@github-work:YourWorkUsername/YourRepo.git

Troubleshooting

SSH Authentication Issues

If you get "Permission denied (publickey)" when pushing or cloning, check:

  • The repository's Git remote URL is using the correct host alias.
  • Your SSH keys are added to the ssh-agent.
  • Your public key is added to the corresponding GitHub account.

Commit Author Incorrect

If your commits are showing under the wrong GitHub account, check the user.email in your Git config.

Multiple Accounts on One Repo

Generally, each Git repository has a single remote URL (origin) and thus a single account context. If you need to contribute to one repo from two accounts, you'd normally use separate clones or change remote URLs when needed.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gitctx-0.1.1.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gitctx-0.1.1-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file gitctx-0.1.1.tar.gz.

File metadata

  • Download URL: gitctx-0.1.1.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for gitctx-0.1.1.tar.gz
Algorithm Hash digest
SHA256 cbd787adcd015fcf3f4f2213b0c6ebbd768576b744678dd9fcd375228ae4db1d
MD5 da2a6e3684a6b0b1de355bace1e1faf3
BLAKE2b-256 7e45c0abca1affe4c0a02e8a8b67ca4c159d98c2efb3e36476a6d789bac20c58

See more details on using hashes here.

File details

Details for the file gitctx-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: gitctx-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for gitctx-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 703e8ec1a5264feaedd321327d07e00355b1c7df3b068a17629239640fa6aa13
MD5 006741b34d3093bf021fcc37d85bbc71
BLAKE2b-256 d4f493521644b5048cb32fc6d982f60108b02c9b43e9c950d0259f72e8e28f2a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page