Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Create a list of git users and easily switch between them. Handy for work vs personal repositories

branch: master
README.rdoc

gitswitch

Easily set/switch your current git user info for a git repo .git/config or your global ~/.gitconfig file.

This gem should come in handy if you have work and personal repositories. It also might help with switching between users while pair programming.

Would you rather type “git config user.email 'me@work.com'”, etc. or type “gitswitch switch work”? If you answered the latter, check out this gem.

Install

# gem install gitswitch

Usage

First, establish a default ~/.gitswitch file using the git info you already have in your ~/.gitconfig file

# gitswitch init

Gitswitch users file ~/.gitswitch not found.  Would you like to create one? (y/n): y
Adding your global .gitconfig user info to the "default" tag...
Current git user information:
  Name:   Joe Alba
  E-mail: joe@home.com

Now, add a new git user tag

# gitswitch add

Enter a tag to describe this git user entry: work
E-mail address: jalba@work.com
Name (ENTER to use "Joe Alba"): Joseph M. Alba

Set specific user info to your current git repository by updating .git/config

# gitswitch switch work  # Update .git/config with your 'work' git user info
Switching git user to "work" tag for the current repository (Joseph M. Alba <jalba@work.com>).

# gitswitch switch       # User info from your 'default' tag is used if you don't specify a tag
Switching git user to "default" tag for the current repository (Joe Alba <joe@home.com>).

List all the gitswitch user tags/info you have stored

# gitswitch list

Current git user options --
default:
  Name:   Joe Alba
  E-mail: joe@home.com
work:
  Name:   Joseph M. Alba
  E-mail: jalba@work.com

Update a current entry. [TAG] parameter is optional. If omitted, you'll see a list.

# gitswitch update [TAG]

Delete a current entry. [TAG] parameter is optional. If omitted, you'll see a list.

# gitswitch delete [TAG]

Update your global .git user instead of your current repository

# gitswitch global work

Show your current git user info. If you are in a git repo directory, it will show you the info associated with the current repository. Outside a repo (or if you use the –global option), it will show you the info from your global .git config.

# gitswitch info

What's with all the aliases for each task?

I initially wrote the gem using optparse and used the '-r' style params to keep the commands as short as possible. Now, I've decided to lean toward a rake-style descriptive method of passing commands – which meshes well with the way Thor likes to do things. But the old command line options still work fine in case you got used to it.

Recent changes (2012 edition)

I've learned a few things, taken some inspiration from David Copeland's “Build Awesome Command-Line Applications in Ruby” book, and stolen the idea of making everything a class method from Hashrocket's hitch gem.

In Ruby 1.9, command line argument strings get frozen, which makes gsub! unhappy. I wasn't on 1.9 two years ago, and my tests are far too incomplete for Travis CI to catch this bug. But alas, it is now fixed.

I've made the first steps toward returning reasonable exit status codes. A failed git command will not yet throw a proper exit code.

Something went wrong with that request. Please try again.