├── GPG_SETUP.md ├── LICENSE ├── README.md ├── git-identity ├── git-identity.1.ronn ├── git-identity.bash-completion ├── git-identity.zsh-completion ├── man └── git-identity.1.gz └── package.sh /GPG_SETUP.md: -------------------------------------------------------------------------------- 1 | Setting up GPG for Git 2 | ====================== 3 | 4 | If you want to use the GPG feature within `git`, there are a few steps for you to follow. These steps are described at many places, but a reminder never hurts. 5 | 6 | Generating a new key 7 | -------------------- 8 | 9 | If you don't have any GPG key yet, you can generate it from a terminal (or Git Bash for Windows) using the following command: 10 | 11 | $ gpg --gen-key 12 | 13 | Follow the wizard and answer the questions about your identity (name, email address). It's advised to leave the default values, but if you wish extra security, chose a keysize of 4096. 14 | Once generated, you can export your keys via the following commands: 15 | 16 | $ gpg --export --armor user@example.com > public.asc 17 | $ gpg --export-secret-keys -o private.gpg user@example.com 18 | $ gpg --output revokecert.asc --gen-revoke user@example.com 19 | 20 | This will output three different files: 21 | 22 | * `public.asc` contains your public key. Copy its content and [send it to GitHub](https://help.github.com/articles/adding-a-new-gpg-key-to-your-github-account/) or any other git service you use 23 | * `private.gpg` contains your private key. This one needs to be put on a safe place. You must **avoid publishing somewhere at all cost** 24 | * `revokecert.asc` contains a certification for revoking your keys. Simply put, you'll need it only if your keys gets compromised 25 | 26 | Importing an existing key 27 | ------------------------- 28 | 29 | If you already have a GPG key that you wish to use for signing your commits, you must first import it to your system (if it's not present). 30 | 31 | Check which keys you already have: 32 | 33 | $ gpg --list-secret-keys 34 | 35 | If your key is not in there, you can import it: 36 | 37 | $ gpg --import myprivatekey.gpg 38 | 39 | Check it has been imported: 40 | 41 | $ gpg --list-secret-keys --keyid-format LONG 42 | 43 | Copy the ID of your private key and register this key in `git-identity`: 44 | 45 | $ git identity --define-gpg 46 | 47 | Additional resources 48 | -------------------- 49 | 50 | Here are some interesting resources you might want to read if you wish to go deeper on GPG with git: 51 | 52 | * [Generating a new GPG key](https://help.github.com/articles/generating-a-new-gpg-key/) 53 | * [Adding a new GPG key to your GitHub account](https://help.github.com/articles/adding-a-new-gpg-key-to-your-github-account/) 54 | * [Installing your GPG key in git](https://help.github.com/articles/telling-git-about-your-gpg-key/) 55 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 2 | Version 2, December 2004 3 | 4 | Copyright (C) 2012 François Vaux 5 | 6 | Everyone is permitted to copy and distribute verbatim or modified 7 | copies of this license document, and changing it is allowed as long 8 | as the name is changed. 9 | 10 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 11 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 12 | 13 | 0. You just DO WHAT THE FUCK YOU WANT TO. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | git-identity 2 | ============ 3 | 4 | You often use Git in different contexts, like at work and for open-source 5 | projects. You may then want to use different user names/email pairs to identify 6 | yourself. 7 | 8 | This is not an important part of your work, and setting this up should be really 9 | fast. That's where `git-identity` comes in: setting up your identity information only takes one command with it. 10 | 11 | *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. 12 | 13 | Installing 14 | ---------- 15 | 16 | Simply link or copy the `git-identity` in a directory that's in your `PATH`, Git 17 | will pick it up and make it available as `git identity`. 18 | 19 | $ ln -s git-identity ~/bin/git-identity 20 | 21 | 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`. 22 | 23 | Then you may setup a default identity with the following command (see Usage for more information): 24 | 25 | $ git identity --define default Me me@example.org 26 | 27 | To get bash completion, just source the `git-identity.bash-completion` file 28 | in your initialization scripts, such as `.bashrc`. 29 | 30 | To get zsh completion, move the `git-identity.zsh-completion` file to a location present in your `$FPATH`, renaming the file to `_git-identity`. 31 | 32 | You can also use [basher](https://github.com/basherpm/basher) to install git-identity: 33 | 34 | $ basher install madx/git-identity 35 | 36 | Usage 37 | ----- 38 | 39 | Add an identity: 40 | 41 | $ git identity --define [] [] 42 | 43 | Add a GPG key to the identity (see GPG specific information below) 44 | 45 | $ git identity --define-gpg 46 | Added GPG key DA221397A6FF5EZZ to [default] user (GPG key: DA221397A6FF5EZZ) 47 | 48 | Add a SSH key to the identity 49 | 50 | $ git identity --define-ssh 51 | Added SSH key id_rsa_anotheraccount to [default] user (SSH key: id_rsa_anotheraccount) 52 | 53 | Print the current identity: 54 | 55 | $ git identity 56 | Current identity: [default] user 57 | 58 | Change identity: 59 | 60 | $ git identity user2 61 | Using identity: [default2] user2 62 | 63 | Update identity: 64 | 65 | $ git identity --update 66 | Using identity: [user] First Last (SSH key: id_rsa_user_new_key) 67 | These are the changes: 68 | 1,2c1,2 69 | < core.sshcommand ssh -i ~/.ssh/id_rsa_user 70 | < user.email user@example.com 71 | --- 72 | > core.sshcommand ssh -i ~/.ssh/id_rsa_user_new_key 73 | > user.email user_new_email@example.com 74 | 75 | List all identities: 76 | 77 | $ git identity --list 78 | Available identities: 79 | [default] user 80 | [default2] user2 81 | 82 | Listing raw identities: 83 | 84 | $ git identity --list-raw 85 | default 86 | default2 87 | 88 | Deleting an identity: 89 | 90 | $ git identity --remove 91 | 92 | Printing the raw identity (for use in scripts) 93 | 94 | $ git identity --print 95 | $ git identity --print 96 | 97 | Priniting the local settings 98 | 99 | $ git identity --get-settings 100 | core.sshcommand ssh -i ~/.ssh/id_rsa_user 101 | user.email user@example.com 102 | user.identity user 103 | user.name First Last 104 | 105 | Retriving GIT_SSH_COMMAND or running command with that in the environment: 106 | 107 | $ git identity -c my_other_identity 108 | GIT_SSH_COMMAND="ssh -i ~/.ssh/id_rsa_myotheridentity" 109 | 110 | $ git identity -c my_other_identity git clone git@github.com:me/myrepo.git 111 | Cloning into 'myrepo'... 112 | 113 | Setting up GPG 114 | -------------- 115 | 116 | More information about how to use GPG with `git-identity` may be found in [GPG_SETUP.md](GPG_SETUP.md) 117 | 118 | Setting up SSH 119 | -------------- 120 | 121 | If you have a valid SSH key associate to the agent you do not have to do anything beside `git identity --define-ssh `. 122 | 123 | This sets `core.sshCommand="ssh -i ~/ssh/ssh-file"` in the local git config when using that identity 124 | 125 | ### Creating a new identity 126 | 127 | ssh-keygen -t rsa -b 4096 -C "yourname@yourdomain" -f ~/.ssh/id_rsa_anotheraccount 128 | ssh-add id_rsa_anotheraccount 129 | 130 | ### Debugging a ssh connection problem 131 | 132 | git identity --define-ssh 133 | 134 | With `verbosity=1` it will use `ssh -v`. 135 | With `verbosity=2` it will use `ssh -vvv`. -------------------------------------------------------------------------------- /git-identity: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # TODO: Support non-stardard identity store 4 | 5 | # shellcheck disable=SC2034 6 | USAGE="$(cat <<'EOF' 7 | [-d | --define] [] [] 8 | or: git identity [--define-gpg] 9 | or: git identity [--define-ssh] [] 10 | or: git identity [-p | --print] [] 11 | or: git identity [-s | --get-settings] 12 | or: git identity [-r | --remove] 13 | or: git identity [-l | --list] 14 | or: git identity [-R | --list-raw] 15 | or: git identity [-u | --update] 16 | or: git identity [-c | --get-shell-command] [] [] 17 | or: git identity 18 | 19 | Specific git-identity actions: 20 | -d, --define define new identity and optionally specify ssh-file and gpg key 21 | --define-gpg add gpg signature to the identity 22 | --define-ssh add ssh key to an identity. If it does not have a path, assume '~/.ssh' 23 | verbosity (0,1,2) of the ssh agent can also be specified 24 | -p, --print print an indenttity or the current one 25 | -r, --remove remove an identity 26 | -s, --get-settings get the current settings that git-identity can changes 27 | -l, --list list all the identities 28 | -R, --list-raw list all identities without details 29 | -u, --update refresh the local settings with the global settings of the current identity 30 | -c,--get-shell-command get GIT_SSH_COMMAND environment variable for for an identity 31 | if it followed by more parameter, execute a command with it 32 | EOF 33 | )" 34 | 35 | lookup () { 36 | local identity="$1" 37 | local key="$2" 38 | 39 | git config --get "identity.$identity.$key" 40 | } 41 | 42 | format_identity () { 43 | local identity="$1" 44 | 45 | echo "[$identity] $(format_raw_identity "$identity")" 46 | } 47 | 48 | format_raw_identity () { 49 | local identity gpgkey sshkey sshkeyverbosity output 50 | identity="$1" 51 | gpgkey="$(lookup "$identity" signingkey)" 52 | sshkey="$(lookup "$identity" sshkey)" 53 | sshkeyverbosity="$(lookup "$identity" sshkeyverbosity)" 54 | 55 | 56 | output="$(lookup "$identity" name) <$(lookup "$identity" email)>" 57 | if [ -n "$gpgkey" ] 58 | then 59 | output="$output (GPG key: $gpgkey)" 60 | fi 61 | 62 | if [ -n "$sshkey" ]; 63 | then 64 | local verbosity="" 65 | if [ -n "$sshkeyverbosity" ]; 66 | then 67 | verbosity=" with verbosity $sshkeyverbosity" 68 | fi 69 | output="$output (SSH key: $sshkey$verbosity)" 70 | fi 71 | 72 | echo "$output" 73 | } 74 | 75 | # TODO: This should return an array ()? 76 | get_ssh_command () { 77 | local identit sshkey sshkeyverbosity 78 | identity="$1" 79 | sshkey="$(lookup "$identity" sshkey)" 80 | sshkeyverbosity="$(lookup "$identity" sshkeyverbosity)" 81 | 82 | if [ -n "$sshkey" ]; 83 | then 84 | local verbosity="" 85 | case $sshkeyverbosity in 86 | 1) verbosity="-v " ;; 87 | 2) verbosity="-vvv " ;; 88 | *) verbosity="" ;; 89 | esac 90 | 91 | if [[ $sshkey != '/'* ]] && [[ $sshkey != '.'* ]] 92 | then 93 | sshkey="$HOME/.ssh/$sshkey" 94 | fi 95 | echo "ssh $verbosity-i $sshkey" 96 | else 97 | echo '' 98 | fi 99 | } 100 | 101 | env_ssh_command () { 102 | local identity name sshCommand 103 | identity="$1" 104 | shift 105 | 106 | if [ "x$identity" = "x" ]; then 107 | identity="$(git config user.identity)" 108 | fi 109 | 110 | if [ -z "$identity" ]; 111 | then 112 | echo "You need to specify an identity or being in a repository with an identity set" 113 | else 114 | name="$(lookup "$identity" name)" 115 | if [ -n "$name" ]; 116 | then 117 | sshCommand="$(get_ssh_command "$identity")" 118 | if [ $# == 0 ] 119 | then 120 | echo "GIT_SSH_COMMAND=\"$sshCommand\"" 121 | else 122 | GIT_SSH_COMMAND="$sshCommand" "$@" 123 | fi 124 | else 125 | echo "Identity $identity does not exist. Doing nothing..." 126 | fi 127 | fi 128 | } 129 | 130 | use_identity () { 131 | local identity name email gpgkey sshCommand 132 | identity="$1" 133 | name="$(lookup "$identity" name)" 134 | email="$(lookup "$identity" email)" 135 | gpgkey="$(lookup "$identity" signingkey)" 136 | sshCommand="$(get_ssh_command "$identity")" 137 | 138 | if [ -n "$name" ]; 139 | then 140 | echo "Using identity: $(format_identity "$identity")" 141 | git config user.identity "$identity" 142 | git config user.name "$name" 143 | git config user.email "$email" 144 | 145 | # Enable or disable GPG key usage 146 | if [ -n "$gpgkey" ]; 147 | then 148 | git config user.signingkey "$gpgkey" 149 | git config commit.gpgsign true 150 | git config tag.gpgsign true 151 | else 152 | git config --unset user.signingkey 153 | git config --unset commit.gpgsign 154 | git config --unset tag.gpgsign 155 | fi 156 | 157 | # Enable or disable SSH key usage 158 | if [ -n "$sshCommand" ]; 159 | then 160 | git config core.sshCommand "$sshCommand" 161 | else 162 | if git config core.sshCommand &>/dev/null; then 163 | git config --unset core.sshCommand || true 164 | fi 165 | fi 166 | else 167 | echo "Identity $identity does not exist. Doing nothing..." 168 | print_current_identity 169 | fi 170 | } 171 | 172 | update_identity () { 173 | local identity prev_settings curr_settings diff_string 174 | identity="$(git config user.identity)" 175 | prev_settings=$(get_current_settings "$identity" | sed -e 's/^/ /') 176 | use_identity "$identity" 177 | curr_settings=$(get_current_settings "$identity" | sed -e 's/^/ /') 178 | diff_string="$(diff --color=always <(echo "$prev_settings") <(echo "$curr_settings"))" 179 | if [ -n "$diff_string" ]; 180 | then 181 | echo "These local setting changed:" 182 | echo "$diff_string" 183 | else 184 | echo "Settings are current. No changes were made." 185 | fi 186 | } 187 | 188 | list_raw_identities () { 189 | git config --get-regexp '^identity\.' | cut -d"." -f2 | sort -u 190 | } 191 | 192 | list_identities () { 193 | local identities 194 | identities="$(list_raw_identities)" 195 | 196 | echo "Available identities:" 197 | for identity in $identities; do 198 | format_identity "$identity" 199 | done 200 | } 201 | 202 | print_raw_identity () { 203 | local identity name 204 | identity="$1" 205 | 206 | if [ "x$identity" = "x" ]; then 207 | identity="$(git config user.identity)" 208 | fi 209 | 210 | if [ -z "$identity" ]; 211 | then 212 | echo "You need to specify an identity or being in a repository with an identity set" 213 | else 214 | name="$(lookup "$identity" name)" 215 | if [ -n "$name" ]; 216 | then 217 | format_raw_identity "$identity" 218 | else 219 | echo "Identity $identity does not exist." 220 | fi 221 | fi 222 | } 223 | 224 | print_current_identity () { 225 | local identity 226 | identity="$(git config user.identity)" 227 | 228 | if [ -n "$identity" ]; 229 | then 230 | echo "Current identity: $(format_identity "$identity")" 231 | else 232 | echo "Current identity: no identity set" 233 | fi 234 | } 235 | 236 | get_current_settings () { 237 | git config --local --get-regexp '^(user\.|(commit|tag)\.gpgsign|core.ssh[cC]ommand)' | sort -u 238 | } 239 | 240 | # TODO: Make this interactive, at least for the code name/email 241 | define_identity () { 242 | local identity="$1" 243 | local name="$2" 244 | local email="$3" 245 | local sshkey="$4" 246 | local gpgkey="$5" 247 | 248 | git config --global identity."$identity".name "$name" 249 | git config --global identity."$identity".email "$email" 250 | 251 | if [ -n "$sshkey" ]; 252 | then 253 | define_ssh "$identity" "$sshkey" 254 | fi 255 | 256 | if [ -n "$gpgkey" ]; 257 | then 258 | define_gpg "$identity" "$gpgkey" 259 | fi 260 | 261 | echo "Created $(format_identity "$identity")" 262 | echo "Enter 'git identity $identity' to use it in the current repository." 263 | } 264 | 265 | remove_identity () { 266 | local identity formated_identity 267 | identity="$1" 268 | formated_identity="$(format_identity "$identity")" 269 | 270 | git config --global --remove-section identity."$identity" 271 | echo "Removed $formated_identity" 272 | } 273 | 274 | define_gpg () { 275 | local indentity gpgkey name current_identity 276 | identity="$1" 277 | gpgkey="$2" 278 | name="$(lookup "$identity" name)" 279 | 280 | if [ -n "$name" ]; 281 | then 282 | git config --global identity."$identity".signingkey "$gpgkey" 283 | echo "Added GPG key $gpgkey to $(format_identity "$identity")" 284 | 285 | current_identity="$(git config user.identity)" 286 | if [ "$current_identity" == "$identity" ] 287 | then 288 | use_identity "$identity" 289 | fi 290 | else 291 | echo "Error: could not define GPG key for undefined identity '$identity'" 292 | fi 293 | } 294 | 295 | define_ssh () { 296 | local identity sshkey sshkeyverbosity name current_identity 297 | local identity="$1" 298 | local sshkey="$2" 299 | local sshkeyverbosity="$3" 300 | name="$(lookup "$identity" name)" 301 | 302 | if [ -n "$name" ]; 303 | then 304 | git config --global identity."$identity".sshkey "$sshkey" 305 | echo "Added SSH key $sshkey to $(format_identity "$identity")" 306 | 307 | if [ -n "$sshkeyverbosity" ]; 308 | then 309 | git config --global identity."$identity".sshkeyverbosity "$sshkeyverbosity" 310 | fi 311 | 312 | current_identity="$(git config user.identity)" 313 | if [ "$current_identity" == "$identity" ] 314 | then 315 | use_identity "$identity" 316 | fi 317 | else 318 | echo "Error: could not define SSH key for undefined identity '$identity'" 319 | fi 320 | } 321 | 322 | IDENTITY="$1" 323 | 324 | check_arguments () { 325 | if [ "$1" -lt "$2" ]; then 326 | usage 327 | exit 1 328 | fi 329 | } 330 | 331 | # For the some commands, it is ok not being in a git folder 332 | case $IDENTITY in 333 | -l|--list|-R|--list-raw|-d|--define|--define-gpg|--define-ssh|-r|--remove|-p|--print|-c|--set-shell-command) 334 | # To prevent git-sh-setup to error out with 'fatal: not a git repository (or any of the parent directories): .git' 335 | NONGIT_OK=1 336 | esac 337 | SUBDIRECTORY_OK=1 338 | # shellcheck source=/usr/lib/git-core/git-sh-setup 339 | . "$(git --exec-path)/git-sh-setup" 340 | 341 | case $IDENTITY in 342 | "") print_current_identity ;; 343 | 344 | -d|--define) 345 | shift 346 | check_arguments $# 3 347 | define_identity "$1" "$2" "$3" "$4" "$5" 348 | ;; 349 | 350 | --define-gpg) 351 | shift 352 | check_arguments $# 2 353 | define_gpg "$1" "$2" 354 | ;; 355 | 356 | --define-ssh) 357 | shift 358 | check_arguments $# 2 359 | define_ssh "$1" "$2" "$3" 360 | ;; 361 | 362 | -p|--print) 363 | shift 364 | print_raw_identity "$1" 365 | ;; 366 | 367 | -s|--get-settings) get_current_settings ;; 368 | 369 | -r|--remove) 370 | shift 371 | check_arguments $# 1 372 | remove_identity "$1" 373 | ;; 374 | 375 | -l|--list) list_identities ;; 376 | 377 | -R|--list-raw) list_raw_identities ;; 378 | 379 | -u|--update) update_identity "$1" ;; 380 | 381 | -c|--get-shell-command) 382 | shift 383 | env_ssh_command "$@" 384 | ;; 385 | 386 | *) use_identity "$IDENTITY" ;; 387 | esac 388 | -------------------------------------------------------------------------------- /git-identity.1.ronn: -------------------------------------------------------------------------------- 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 me@example.org 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 [] [] 50 | 51 | Add a GPG key to the identity (see GPG specific information below) 52 | 53 | $ git identity --define-gpg 54 | Added GPG key DA221397A6FF5EZZ to [default] user (GPG key: DA221397A6FF5EZZ) 55 | 56 | Add a SSH key to the identity 57 | 58 | $ git identity --define-ssh 59 | Added SSH key id_rsa_anotheraccount to [default] user (SSH key: id_rsa_anotheraccount) 60 | 61 | Print the current identity: 62 | 63 | $ git identity 64 | Current identity: [default] user 65 | 66 | Change identity: 67 | 68 | $ git identity user2 69 | Using identity: [default2] user2 70 | 71 | Update identity: 72 | 73 | $ git identity --update 74 | Using identity: [user] First Last (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 | < user.email user@example.com 79 | --- 80 | > core.sshcommand ssh -i ~/.ssh/id_rsa_user_new_key 81 | > user.email user_new_email@example.com 82 | 83 | List all identities: 84 | 85 | $ git identity --list 86 | Available identities: 87 | [default] user 88 | [default2] user2 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 99 | 100 | Printing the raw identity (for use in scripts) 101 | 102 | $ git identity --print 103 | $ git identity --print 104 | 105 | Priniting the local settings 106 | 107 | $ git identity --get-settings 108 | core.sshcommand ssh -i ~/.ssh/id_rsa_user 109 | user.email user@example.com 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 git@github.com: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 `. 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 141 | 142 | With `verbosity=1` it will use `ssh -v`. 143 | With `verbosity=2` it will use `ssh -vvv`. -------------------------------------------------------------------------------- /git-identity.bash-completion: -------------------------------------------------------------------------------- 1 | # vim: ft=sh: 2 | # shellcheck disable=SC2154 3 | _git_identity () { 4 | # Needs the bash-completion for git proper 5 | [ -n "$__git_whitespacelist" ] || return; 6 | 7 | _get_comp_words_by_ref -n =: cur words 8 | # git identity -h | tr '|' '\n'|grep -oE '\-.+'|cut -f1 -d']' |tr '\n' ' ' 9 | # The grep regex is a bit hack-y, but this is just over-optimizing anyway 10 | # Whenever you add more commands just come add them here 11 | local commands="-d --define --define-gpg --define-ssh -p --print -s --get-settings -r --remove -l --list -R --list-raw -u --update -h -c --get-shell-command" 12 | 13 | case "$cur" in 14 | -*) 15 | __gitcomp "$commands" 16 | ;; 17 | *) 18 | __gitcomp "$(git identity --list-raw)" 19 | ;; 20 | esac 21 | } 22 | -------------------------------------------------------------------------------- /git-identity.zsh-completion: -------------------------------------------------------------------------------- 1 | #compdef git-identity 2 | local -a options identities 3 | identities=( $(git identity --list-raw) ) 4 | options=( 5 | '-h:Show help' 6 | {-d,--define}':Define a new identity' 7 | {--define-gpg}':Assign a GPG key with an identity' 8 | {--define-ssh}':Add a ssh key for the identity' 9 | {-p,--print}':Print an identity' 10 | {-s,--get-settings}':Print current local settings' 11 | {-r,--remove}':Remove an identity' 12 | {-l,--list}':List all identities' 13 | {-R,--list-raw}':List only the names of all identities' 14 | {-u,--update}':Update local settings based on the current identity' 15 | {-c,--get-shell-command}':Get GIT_SSH_COMMAND for an identiy or current identity' 16 | ) 17 | 18 | if (( CURRENT < 3 )); then 19 | _alternative "ids:Identities:($identities)" "opts:Options:{_describe 'Identities' options}" 20 | fi 21 | -------------------------------------------------------------------------------- /man/git-identity.1.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/madx/git-identity/a8efec6f42a7bb4bc197b25400039da16adf6e99/man/git-identity.1.gz -------------------------------------------------------------------------------- /package.sh: -------------------------------------------------------------------------------- 1 | ## 2 | # Basher package file 3 | 4 | BINS='git-identity' 5 | 6 | BASH_COMPLETIONS='git-identity.bash-completion' 7 | 8 | ZSH_COMPLETIONS='git-identity.zsh-completion' 9 | --------------------------------------------------------------------------------