Giter Club home page Giter Club logo

git-identity-manager's Introduction

Git Identity Manager Build Status

Ever find that managing multiple git identities is a pain? This git transport attempts to make it less painful.

Knowing who you are can be painful

Image credit PBS.org

Requirements

bash, awk, sed, and openssh are available by default on Mac OS X, BSD, and most flavors of GNU/Linux. Git likely needs to be installed. On Mac OS X, installing Git through homebrew is recommended.

Installation

Add git-idm script to your $PATH and make it executable. Then, you can access the script via git idm. See git idm help for usage.

Uninstall

Remove all data stored in $HOME/.gitconfig related to git idm. This will not affect settings used by git.

git idm uninstall

Quick start

Add your first identity.

git idm add jcool --name "Joe Cool" --email [email protected] --key ~/.ssh/id_rsa

Activate your identity.

git idm use jcool

Show which identity is active.

git idm active

List all known identities.

git idm list

For more commands see git idm help.

Autotracked identities

You can configure your Git identities to automatically switch depending on what directory you have cloned. For example, let's say you have personal projects and work projects on the same laptop. Assuming you have a work identity and a personal identity configured, the following commands would help you auto-switch identites for repositories under designated paths.

git idm track work --directory ~/git/work
git idm track personal --directory ~/git/github

You can list what directories are tracked by a given identity.

git idm list work --tracked

Which will return output like the following.

work identity will automatically apply to the following directories:
    /home/user/git/work/

Verify the identity has switched with git config user.email.

cd ~/git/work
mkdir example
cd example/
git init

# the email identity should show your work email
git config user.email

License

MIT License

git-identity-manager's People

Contributors

0xnero avatar samrocketman avatar vvdaal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

git-identity-manager's Issues

Change git idm automatically based on project directory location

https://dev.to/maxlmator/maintaining-different-git-identities

It would be nice for identities to auto-select based on a local directory (optionally given).

[includeIf "gitdir:~/git/github/"]
    path = /home/sam/.gitconfig_idm_github

And the contents of /home/sam/.gitconfig_idm_github would be...

[user]
    name = Sam Gleske
    email = [email protected]
[core]
    sshCommand = ssh -i /home/sam/.ssh/id_rsa -o IdentitiesOnly=yes -F /dev/null

Assuming that the git idm identity is...

[user]
    name = Sam Gleske
    email = [email protected]
    activeidm = github
[gitidm "github"]
    name = Sam Gleske
    email = [email protected]
    sshKey = /home/sam/.ssh/id_rsa
    sshCommand = ssh -i /home/sam/.ssh/id_rsa -o IdentitiesOnly=yes -F /dev/null

This will require a minimum version of git 2.13.0 for this.

Brainstorming feature

I think it makes sense to add this as a sub-command git idm directory which associates the identity name with the directory.

# personal projects
git idm directory add github ~/git/github/

# work projects
git idm directory add work ~/git/work/

# generically
git idm directory [add|remove] [git idm identity] [project path to apply identity]

We could tie the identity with an idm subkey in .gitconfig like:

[includeIf "gitdir:~/git/github/"]
    idm = github
    path = /home/sam/.gitconfig_idm_github

When removing an identity we'll want it to search for all includeIf settings where idm key is equal to the identity being removed. We'll also want to delete the file.

Using the prefix .gitconfig_idm_[git idm identity] for the file seems like the best way to avoid clashing with potential user configuration files.

git idm active doesn't show the tracked ID

// Track ~/GitRepos/personal to use "personal" ID
~/GitRepos/personal
$ git idm track personal --directory $(pwd)
git config --file /Users/calvin/.gitconfig_idm_personal user.name Calvin Sangbin Park
git config --file /Users/calvin/.gitconfig_idm_personal user.email [email protected]
git config --file /Users/calvin/.gitconfig_idm_personal core.sshCommand ssh -i /Users/calvin/.ssh/id_rsa.github-personal.NVMBP -o IdentitiesOnly=yes -F /dev/null
git config --global includeIf.gitdir:/Users/calvin/GitRepos/personal/.idm personal
git config --global includeIf.gitdir:/Users/calvin/GitRepos/personal/.path /Users/calvin/.gitconfig_idm_personal

// Go to a root of all repos dir
~/GitRepos
$ cd ..

// Check that "work" ID is active
~/GitRepos
$ git idm active
work
    name=Calvin Park
    [email protected]
    sshkey=/Users/calvin/.ssh/id_rsa
    sshcommand=ssh -i /Users/calvin/.ssh/id_rsa -o IdentitiesOnly=yes -F /dev/null
WARNING: /Users/calvin/.ssh/id_rsa has not been added to ssh-agent.  To fix run: ssh-add '/Users/calvin/.ssh/id_rsa'

// Go into ~/GitRepos/personal/book/jenkins-shared-library/ where git idm tracks to use "personal" ID
~/GitRepos
$ cd personal/book/jenkins-shared-library/

// git idm active reports that it's using "work" ID
~/GitRepos/personal/book/jenkins-shared-library
$ git idm active
work
    name=Calvin Park
    [email protected]
    sshkey=/Users/calvin/.ssh/id_rsa
    sshcommand=ssh -i /Users/calvin/.ssh/id_rsa -o IdentitiesOnly=yes -F /dev/null
WARNING: /Users/calvin/.ssh/id_rsa has not been added to ssh-agent.  To fix run: ssh-add '/Users/calvin/.ssh/id_rsa'

// when in reality it's using "personal" ID
~/GitRepos/personal/book/jenkins-shared-library
$ git config user.email
[email protected]

A following git commit showed that "personal" ID is indeed is active, which means git track is working.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.