Skip to content

Instantly share code, notes, and snippets.

@vuon9
Last active March 22, 2020 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vuon9/74a003e7dc2c60b56ce8bb2642b7562e to your computer and use it in GitHub Desktop.
Save vuon9/74a003e7dc2c60b56ce8bb2642b7562e to your computer and use it in GitHub Desktop.
Git configuration for multiple identities
; put this content into ~/.gitconfig
[core]
editor = 'code' --wait
[url "ssh://redirect-to-somewhere"]
insteadOf = https://scm-git-private.server.com/
[alias]
; https://dev.to/nishina555/how-to-ignore-files-already-managed-with-git-locally-19oo
; ignore files, assumes change locally, git will not manage it
ignore = update-index --skip-worktree
unignore = update-index --no-skip-worktree
ignored = !git ls-files -v | grep "^S"
; ignore files, assumes unchanged locally
untrack = update-index --assume-changed
retrack = update-index --no-assume-changed
untracked = !git ls-files -v | grep "^h"
; others
lastchange = show
aliases = config --global --get-regexp ^alias\\.
; Company
[includeIf "gitdir/i:~/workspace/company/"]
path = ~/.gitconfig.company
; Personal
[includeIf "gitdir/i:~/workspace/me/"]
path = ~/.gitconfig.me
  1. Generate ssh keys by following one of these tutorials:

Bitbucket tutorial

Gitlab tutorial

Github tutorial

  1. After added SSH keys successfully, you should check by listing ssh keys:
ssh-add -l
  1. Configure ~/.ssh/config:
# Work
Host git.company.com
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_rsa

# Personal
Host github.com gitlab.com bitbucket.org
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_rsa_individual
  1. Test added SSH keys
ssh -T git@git.company.com
ssh -T git@gitlab.com
ssh -T git@bitbucket.org
ssh -T git@github.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment