Skip to content

Instantly share code, notes, and snippets.

@ludenus
Last active March 14, 2022 14:26
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 ludenus/0c6714b760447047d18249890fe4c5b5 to your computer and use it in GitHub Desktop.
Save ludenus/0c6714b760447047d18249890fe4c5b5 to your computer and use it in GitHub Desktop.
directory-based separation for personal and work bitbucket

Generate ~/.ssh/id_rsa_git ssh key for personal projects, add public key part to your personal bitbucket account.

Generate ~/.ssh/id_rsa_wrk ssh key for work projects, add public key part to your work bitbucket account.

Create ~/git dir for personal projects.

Create ~/wrk dir for work projects.

Place all pet git repos under ~/git.

Place all work git repos under ~/wrk.

~/.gitconfig

[pull]
	ff = only
  
[includeIf "gitdir:~/wrk/"]
    path = ~/.gitconfig-wrk
    
[includeIf "gitdir:~/git/"]
    path = ~/.gitconfig-git

~/.gitconfig-wrk

[user]
	name = Work Account
	email = work.account@company.com
  
[core]
	sshCommand = ssh -F ~/.ssh/config-wrk

~/.gitconfig-git

[user]
	name = Perr Sonal
	email = perr.sonal@gmail.com
  
[core]
	sshCommand = ssh -F ~/.ssh/config-git

~/.ssh/config

Host *
    UseKeychain yes

~/.ssh/config-wrk

Include ~/.ssh/config

Host bitbucket.org
  HostName bitbucket.org
  User git
  IdentityFile ~/.ssh/id_rsa_wrk

~/.ssh/config-git

Include ~/.ssh/config

Host bitbucket.org
  HostName bitbucket.org
  User git
  IdentityFile ~/.ssh/id_rsa_git

check:

$ cd ~/git/pet
$ git config user.name
Perr Sonal

$ cd ~/wrk/project
$ git config user.name
Work Account

or git config --list to list full config

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment