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

gitswap-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.

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: gitswap-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 gitswap-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d4f11c0c52ad9921a751d804b1c913ab85f50fea5702f62f5b45d52c4f04b28a
MD5 3b22599913b6c2bc0b89897be2574c17
BLAKE2b-256 915f77d8306b39df0041aa243022028c235005a5883d073788639bb93562e033

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gitswap-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 gitswap-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f7681714bf4106bd47f226efb9b28b01474b6fee4d1782fa46cc66262e49d214
MD5 1eea246aa699b79c71a4ed131d32593b
BLAKE2b-256 a6acc7d334ba624463710e9ebc3c6c9b368af005fd234e80868cd57f8deff823

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