Giter Club home page Giter Club logo

git-identities's Introduction

Git-Identities

User identity management for git

This program is meant to be used by people who work on multiple projects with different Git identities, e.g. students or home-office workers.

Git-Identities allows you to change your Git config's user.name and user.email easily and quickly from a database of known identities, and provides automatic setters and checks to assure you're never committing with the wrong config again.

This requires Git version 2.10+ to work correctly.

Usage

Basics

Every command in this program has a help function by calling it with -h or --help.

The main command is git identities. It allows managing your identities and applying it to different contexts.

With git identities list, you can list all known identities.

With git identities add <id> <name> <email>, you can add a new identity. As <id>, use an identifier that can be used to reference your identity later, it has to be alphanumeric with underscores, not starting with a number.

With git identities apply <id>, the identity is set as the local config's user.name and user.email. You can reset a local choice with git identities use-global.

"current context"

By "current context", the program means the configuration as it would be used by Git in the current directory. This is either the local config in .git/config or a submodule config directory, that has overriden other settings, the global config, or the system-wide config, whatever comes first in this order.

Verifying

The main purpose of the Git-Identities program is to ensure that you're using the right identity.

To accomplish this, you can use

git identities update <id> --paths /path/to/projects1 /path/to/projects2 ...

to set one or more paths, whose subdirectories will honor the given identity. If the program is installed correctly, it will not let you commit if you would commit with a different identity than the one that should be used in the current context.

(You can override this for one time by calling git commit --no-verify, if you need to.)

It will also warn you (but not stop you to commit) if the current context does not match to any identity known to Git-Identities.

Keywords

Git-Identities also supports keywords. They can be set with

git identities update <id> --keywords keyword1 keyword2 ...

An identity with a keyword matches whenever the path contains the keyword, anywhere. Paths are always prioritized, and keywords are prioritized by the order they were specified in the update command.

Paths are recommended and keywords discouraged, as they can prove a bit unpredictable. They have their advantages for verifying, though, sometimes.

Example

Assume we have used

git identities add private "Woalk" "[email protected]"
git identities add work "Name Surname" "[email protected]"

to add two identities.

Assume further that we have a directory structure of /home/woalk/git for private projects, with a subdirectory work for work projects.

So, we use

git identities update private --paths /home/woalk/git
git identities update work --paths /home/woalk/git/work

to set up our identity checks.

If we now want to commit something in our project /home/woalk/git/privateproject1, Git-Identities will ensure it is done with the private identity, which means using Woalk as user.name and [email protected] as user.email.

If we now want to commit something in our project /home/woalk/git/work/topsecretproject1, Git-Identities will ensure it is done with the work identity, which means using Name Surname as user.name and [email protected] as user.email.

Auto-applying

Git-Identities can automatically set the correct config from the settings.

This can either be done manually, by calling

git identities apply --auto

in the respective repository, or by calling

git id-clone <url> ...

instead of git clone when cloning a repository. It will check the destination directory for the applying identity and set it via directly when cloning.

It supports every argument that git clone supports, except [<directory>]. See man git clone for details.

Installation

Script

Use the install.sh script from this directory.

It is a careful script that will tell you everything it will do and provide you with a chance to review the changes before committing them.

After installation, Git-Identities is available via git identities, assuming the main binary installation place chosen in the installation script was in your PATH.

Installation place

It will ask you to move the checked-out repo into a system-wide directory before running the script.

On Linux systems, you can use, for example, /opt. On macOS systems, you can use /usr/local, or /usr/local/opt if you have brew installed.

On Linux, you should chown the repo to root:root for security reasons. On macOS, you can chown it to root:wheel, assuming you're ok with that if you have brew installed.

Optional configuration

You can create additional Git alias commands for better access to Git-Identities, e.g.

git config alias.id identities
git config alias.ic id-clone

to access the commands via git id and git ic.

Author & License

Copyright (C) 2018 Alexander Köster
https://woalk.com
Licensed under the Apache License, Version 2.0 (the "License");
you may not use these files except in compliance with the License.
You may obtain a copy of the License in the file LICENSE in this
project or at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

If you build something better with it, I would love to know and get a PR, but it isn't mandatory.

git-identities's People

Contributors

woalk avatar

Stargazers

 avatar

Watchers

 avatar  avatar

git-identities's Issues

GPG key support

Implement support of GPG key switching based on identity.

GPG keys are also part of an identity and one may not want to commit with the wrong or without GPG key if you have a key for your identity.

  • The key should be optional when calling git identities add <id> <name> <email> [<gpg-id>]
  • The key should be changeable with git identities update --key <gpg-id>
  • The key should be checked when searching for the currently selected identity (most importantly in checks.py):
    • If no key is set, but name and email match an identity with a key (and the same identity does not exist with a key as well), it should be shown as an error and not be committable. It should be shown as a warning in list and show (e.g. mark the selected identity with an exclamation mark instead of an askerisk).
    • If a key is set, but name and email match an identity without key (and the same identity doesn't exist without key), it should also be treated that way.
  • When changing from an identity with a key to an identity without key, the selected key config should be removed.

There's room for discussion on what to check for correct key use.
Suggest commit -S aliases, switch git log aliases to automatically include GPG information based on the repo context, etc.

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.