Manage multiple git accounts

manage-multiple-git-accounts

Hi! Do you have multiple git accounts or you just using one? I have multiple and everytime I reinstall my system I trying to find how I
configured it before… (i finally wrote this together here).

Im using multiple git config file rather than multiple host names (i don’t like to have somethink like git@github-work or git@github-personal).

How it’s work?

First of all you need to create different folders for you personal and work projects (or more folders if you have more accounts). Into each folder
create new .gitconfig file which will looks like this one:

# ~/Work/.gitconfig.work
[user]
email = your@email
name = Your Name

[github]
user = "YourGithubName"

[core]
sshCommand = "ssh -i ~/.ssh/work.pub" # public key for your work profile

You will also need more SSH keys. I using 1Password so I copy only my public keys to the my .ssh folder.

SSH with 1Password

If you want to use 1Passowrd you need to configure ssh. Add following to your ~/.ssh/config file

Host *
    IdentityAgent ~/.1password/agent.sock

SSH With SSH-AGENT

If you want to use more traditional way you will need to configure SSH-AGENT

eval "$(ssh-agent -s)" && 
ssh-add -K ~/.ssh/ 

Then edit your ~/.ssh/config

Host *
    AddKeysToAgent yes
    UseKeychain yes
    IdentityFile ~/.ssh/

OK now you have create your keys and gitconfig files for you profiles. Now you need to tell git to use proper config based on git repository location. Edit ~/gitconfig which will need to looks similar to this:

# ~/.gitconfig

[includeIf "gitdir:~/May/"] # include for all .git projects under May/ 
path = ~/May/.gitconfig.may

[includeIf "gitdir:~/Work/"] # include for all .git projects under Work/
path = ~/Work/.gitconfig.work

[core]
excludesfile = ~/.gitignore      # valid everywhere

You list all your configs with git config --list command.

That’s all

Good! You can now clone repositories from multiple accounts based on in which folder you clonning it.

Total
0
Shares
Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post
postgresql-vs-sqlite

PostgreSQL vs SQLite

Next Post
sql-+-python-+-spark-for-data-science

SQL + Python + Spark for Data Science

Related Posts
irremote-程式庫搭配-adafruit-neopoxel-程式庫的問題

IRRemote 程式庫搭配 Adafruit_NeoPoxel 程式庫的問題

IRremote 是大家使用紅外線遙控實驗最常用的程式庫,由於接收紅外線遙控器訊號與時間極度相關,如果你的程式中有耗時較久的動作,就可能會影響到紅外線訊號接收的正確性。舉例來說,像是大家愛用的 WS2812B 燈串,串接越多顆燈,傳輸所有燈顏色的資料所耗的時間就越久,以底下這個採用 Adafruit_NeoPixel 程式庫顯示呼吸燈效果的程式為例: #include #include #include #define DECODE_NEC Adafruit_NeoPixel leds=Adafruit_NeoPixel(16, 7); void setup() { Serial.begin(115200);…
Read More