|
| 1 | +git-identity |
| 2 | +============ |
| 3 | + |
| 4 | +Name |
| 5 | +---- |
| 6 | + |
| 7 | +git-identity - manage your identity in Git |
| 8 | + |
| 9 | +Description |
| 10 | +----------- |
| 11 | + |
| 12 | +You often use Git in different contexts, like at work and for open-source |
| 13 | +projects. You may then want to use different user names/email pairs to identify |
| 14 | +yourself. |
| 15 | + |
| 16 | +This is not an important part of your work, and setting this up should be really |
| 17 | +fast. That's where `git-identity` comes in: setting up your identity information only takes one command with it. |
| 18 | + |
| 19 | +*Note:* Identities are stored in the global git config. Using an identity copies the setting in the local repo git configuration. If you are changing the global config for one identity does *NOT* propagate the changes to the local repos. You will have use `git identity --update` in the repo folder to update the identity. |
| 20 | + |
| 21 | +Installing |
| 22 | +---------- |
| 23 | + |
| 24 | +Simply link or copy the `git-identity` in a directory that's in your `PATH`, Git |
| 25 | +will pick it up and make it available as `git identity`. |
| 26 | + |
| 27 | + $ ln -s git-identity ~/bin/git-identity |
| 28 | + |
| 29 | +Under Windows, go to System > Advanced System Parameters > Environment Variable. Find the "Path" entry under *system variables* and add the path to where you downloaded `git-identity`. |
| 30 | + |
| 31 | +Then you may setup a default identity with the following command (see Usage for more information): |
| 32 | + |
| 33 | + $ git identity --define default Me [email protected] |
| 34 | + |
| 35 | +To get bash completion, just source the `git-identity.bash-completion` file |
| 36 | +in your initialization scripts, such as `.bashrc`. |
| 37 | + |
| 38 | +To get zsh completion, move the `git-identity.zsh-completion` file to a location present in your `$FPATH`, renaming the file to `_git-identity`. |
| 39 | + |
| 40 | +You can also use [basher](https://github.com/basherpm/basher) to install git-identity: |
| 41 | + |
| 42 | + $ basher install madx/git-identity |
| 43 | + |
| 44 | +Usage |
| 45 | +----- |
| 46 | + |
| 47 | +Add an identity: |
| 48 | + |
| 49 | + $ git identity --define <identity name> <user name> <user email> [<ssh-file>] [<gpgkeyid>] |
| 50 | + |
| 51 | +Add a GPG key to the identity (see GPG specific information below) |
| 52 | + |
| 53 | + $ git identity --define-gpg <identity name> <gpgkeyid> |
| 54 | + Added GPG key DA221397A6FF5EZZ to [default] user <[email protected]> (GPG key: DA221397A6FF5EZZ) |
| 55 | + |
| 56 | +Add a SSH key to the identity |
| 57 | + |
| 58 | + $ git identity --define-ssh <identity name> <ssh-file> |
| 59 | + Added SSH key id_rsa_anotheraccount to [default] user <[email protected]> (SSH key: id_rsa_anotheraccount) |
| 60 | + |
| 61 | +Print the current identity: |
| 62 | + |
| 63 | + $ git identity |
| 64 | + Current identity: [default] user <[email protected]> |
| 65 | + |
| 66 | +Change identity: |
| 67 | + |
| 68 | + $ git identity user2 |
| 69 | + Using identity: [default2] user2 <[email protected]> |
| 70 | + |
| 71 | +Update identity: |
| 72 | + |
| 73 | + $ git identity --update |
| 74 | + Using identity: [user] First Last <[email protected]> (SSH key: id_rsa_user_new_key) |
| 75 | + These are the changes: |
| 76 | + 1,2c1,2 |
| 77 | + < core.sshcommand ssh -i ~/.ssh/id_rsa_user |
| 78 | + |
| 79 | + --- |
| 80 | + > core.sshcommand ssh -i ~/.ssh/id_rsa_user_new_key |
| 81 | + |
| 82 | + |
| 83 | +List all identities: |
| 84 | + |
| 85 | + $ git identity --list |
| 86 | + Available identities: |
| 87 | + [default] user <[email protected]> |
| 88 | + [default2] user2 <[email protected]> |
| 89 | + |
| 90 | +Listing raw identities: |
| 91 | + |
| 92 | + $ git identity --list-raw |
| 93 | + default |
| 94 | + default2 |
| 95 | + |
| 96 | +Deleting an identity: |
| 97 | + |
| 98 | + $ git identity --remove <identity name> |
| 99 | + |
| 100 | +Printing the raw identity (for use in scripts) |
| 101 | + |
| 102 | + $ git identity --print |
| 103 | + $ git identity --print <identity name> |
| 104 | + |
| 105 | +Priniting the local settings |
| 106 | + |
| 107 | + $ git identity --get-settings |
| 108 | + core.sshcommand ssh -i ~/.ssh/id_rsa_user |
| 109 | + |
| 110 | + user.identity user |
| 111 | + user.name First Last |
| 112 | + |
| 113 | +Retriving GIT_SSH_COMMAND or running command with that in the environment: |
| 114 | + |
| 115 | + $ git identity -c my_other_identity |
| 116 | + GIT_SSH_COMMAND="ssh -i ~/.ssh/id_rsa_myotheridentity" |
| 117 | + |
| 118 | + $ git identity -c my_other_identity git clone [email protected]:me/myrepo.git |
| 119 | + Cloning into 'myrepo'... |
| 120 | + |
| 121 | +Setting up GPG |
| 122 | +-------------- |
| 123 | + |
| 124 | +More information about how to use GPG with `git-identity` may be found in [GPG_SETUP.md](GPG_SETUP.md) |
| 125 | + |
| 126 | +Setting up SSH |
| 127 | +-------------- |
| 128 | + |
| 129 | +If you have a valid SSH key associate to the agent you do not have to do anything beside `git identity --define-ssh <identity name> <ssh-file>`. |
| 130 | + |
| 131 | +This sets `core.sshCommand="ssh -i ~/ssh/ssh-file"` in the local git config when using that identity |
| 132 | + |
| 133 | +### Creating a new identity |
| 134 | + |
| 135 | + ssh-keygen -t rsa -b 4096 -C "yourname@yourdomain" -f ~/.ssh/id_rsa_anotheraccount |
| 136 | + ssh-add id_rsa_anotheraccount |
| 137 | + |
| 138 | +### Debugging a ssh connection problem |
| 139 | + |
| 140 | + git identity --define-ssh <identity name> <ssh-file> <verbosity> |
| 141 | + |
| 142 | +With `verbosity=1` it will use `ssh -v`. |
| 143 | +With `verbosity=2` it will use `ssh -vvv`. |
0 commit comments