DEV Community

Cover image for Managing Multiple Git Profiles with Ease: Introducing `gguser`
Shubhendra Singh Chauhan
Shubhendra Singh Chauhan

Posted on

Managing Multiple Git Profiles with Ease: Introducing `gguser`

If you're a developer juggling between work projects, personal side projects, and maybe even some open-source contributions, you're likely familiar with a common frustrationβ€”managing multiple Git identities on the same machine.

Imagine this scenario: You commit changes to your personal project and push them to GitHub, only to realize that your work email is attached to the commit. Or worse, you accidentally push a work-related change using your personal GitHub account. Fixing this means manually updating your Git config each time you switch contexts.

For years, developers have resorted to running:

git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
Enter fullscreen mode Exit fullscreen mode

But this is tedious and error-prone. What if there was a better way?

Meet gguser

gguser is a simple yet powerful CLI tool designed to seamlessly switch between multiple Git user profiles. Whether you're switching between work, personal, or open-source accounts, gguser makes the process effortless.


πŸš€ Installing gguser

Installing gguser is quick and easy. Simply run:

npm install -g gguser
Enter fullscreen mode Exit fullscreen mode

Now, you have gguser available globally, ready to manage your Git profiles.


🎯 How to Use gguser

1️⃣ Adding Git Profiles

Before switching between Git users, you need to define them:

gguser add <profile_name> "<full_name>" "<email>" [ssh_key]
Enter fullscreen mode Exit fullscreen mode

Example:

gguser add work "Shubhendra Chauhan" "work@company.com" ~/.ssh/id_ed25520
gguser add personal "Shubhendra Singh Chauhan" "personal@email.com" ~/.ssh/id_ed25521
Enter fullscreen mode Exit fullscreen mode

Here, the SSH key is optional but useful if you want to authenticate using SSH.


2️⃣ Switching Between Git Profiles

Interactive Selection

Instead of remembering profile names, use:

gguser select
Enter fullscreen mode Exit fullscreen mode

You'll see a list of your configured profiles and can simply pick one.

Quick Switching

If you already know which profile you want to switch to, just run:

gguser <profile_name>
Enter fullscreen mode Exit fullscreen mode

Example:

gguser work
Enter fullscreen mode Exit fullscreen mode

This updates your Git global config instantly.


3️⃣ Checking Your Current Git User

Ever wondered which Git identity is active? Quickly verify using:

gguser now
Enter fullscreen mode Exit fullscreen mode

This command will display the currently configured Git user:

πŸ‘€ Current Git User: Shubhendra Singh Chauhan <personal@email.com>
Enter fullscreen mode Exit fullscreen mode

4️⃣ Managing Your Profiles

Listing All Profiles

To see all configured profiles, run:

gguser list
Enter fullscreen mode Exit fullscreen mode

Removing a Profile

No longer need a profile? Remove it:

gguser remove <profile_name>
Enter fullscreen mode Exit fullscreen mode

πŸ”— Linking a Profile to a Directory

Many developers work on different projects that require different Git identities. For example:

  • Your personal projects live in ~/projects/personal
  • Your work projects live in ~/projects/work

Instead of manually switching Git users each time, you can link a profile to a specific directory:

gguser link work
Enter fullscreen mode Exit fullscreen mode

Now, whenever you enter that directory, gguser will automatically use the correct Git profile.

To unlink:

gguser unlink
Enter fullscreen mode Exit fullscreen mode

πŸ”₯ Why gguser is a Game-Changer

βœ… No more accidental commits with the wrong Git identity

βœ… Seamlessly switch between work, personal, and open-source profiles

βœ… Automatic profile selection based on directories

βœ… Easily manage SSH keys

βœ… Developer-friendly CLI with an interactive selection mode


πŸ’‘ Contribute or Extend gguser

gguser is open-source, and contributions are welcome! If you have ideas for improvements or new features, feel free to submit a pull request. You can check out the repo here:

πŸ”— GitHub: https://github.com/withshubh/gguser

πŸ“¦ NPM: https://www.npmjs.com/package/gguser


🎯 Final Thoughts

For developers working with multiple Git accounts, gguser is a must-have tool. No more wasting time manually updating Git config settings or dealing with incorrect commit histories. Try it out today and simplify your workflow!

Let me know in the comments how gguser has helped you! πŸš€

Top comments (0)