|
| 1 | +# Git multi-account setup |
| 2 | + |
| 3 | +If you facing a **common Git multi-account configuration problem** on a **single laptop**, where: |
| 4 | + |
| 5 | +* **Primary GitHub Account** (used in IntelliJ IDEA, logged in via Microsoft Edge) |
| 6 | +* **Secondary GitHub Account** (used in VS Code, logged in via Brave) |
| 7 | +* **Global Git config** supports only one user at a time (per default setup) |
| 8 | + |
| 9 | +To resolve this and use **two separate GitHub accounts with different IDEs on one machine**, you need to: |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +## ✅ Solution (Fix in 3 Steps) |
| 14 | +### 🔧 Step 1: Manually Create the .ssh Folder |
| 15 | + |
| 16 | +> In PowerShell, run: |
| 17 | +
|
| 18 | +```bash |
| 19 | +mkdir ~/.ssh |
| 20 | +``` |
| 21 | + |
| 22 | +> This creates the hidden .ssh folder inside your user directory (C:\Users\akash). |
| 23 | +
|
| 24 | +--- |
| 25 | + |
| 26 | +Great update — thanks! |
| 27 | + |
| 28 | +From the latest messages, we can clearly see: |
| 29 | + |
| 30 | +* The folder `.ssh` **already exists** ✅ |
| 31 | +* But your command `ssh-keygen -f ~/.ssh/...` **still failed**, saying: |
| 32 | + |
| 33 | + ``` |
| 34 | + Saving key "~/.ssh/id_rsa_akashdip" failed: No such file or directory |
| 35 | + ``` |
| 36 | + |
| 37 | +--- |
| 38 | + |
| 39 | +## ✅ Generate `SSH Keys` for Both Accounts |
| 40 | + |
| 41 | +On Windows, PowerShell doesn't always expand `~` correctly in all commands. |
| 42 | + |
| 43 | +### 🔄 Try this instead (use full path): |
| 44 | + |
| 45 | +#### 🔷 For Primary (akashdip2001): |
| 46 | + |
| 47 | +```powershell |
| 48 | +ssh-keygen -t rsa -C "akashdipXXXXXXX@gmail.com" -f "C:\Users\akash\.ssh\id_rsa_akashdip" |
| 49 | +``` |
| 50 | + |
| 51 | +#### 🔶 For Secondary (Arkadip2007): |
| 52 | + |
| 53 | +```powershell |
| 54 | +ssh-keygen -t rsa -C "arkadipXXXXXXX@gmail.com" -f "C:\Users\akash\.ssh\id_rsa_arkadip" |
| 55 | +``` |
| 56 | + |
| 57 | +📌 Now it should successfully save the keys. |
| 58 | + |
| 59 | +--- |
| 60 | + |
| 61 | +### ✅ Then copy public key with: |
| 62 | + |
| 63 | +```powershell |
| 64 | +type C:\Users\akash\.ssh\id_rsa_akashdip.pub |
| 65 | +``` |
| 66 | + |
| 67 | +> Copy the whole line it prints (starts with `ssh-rsa ...`) and paste it into **GitHub → SSH Keys**. |
| 68 | +
|
| 69 | +## Steps in GitHub |
| 70 | + |
| 71 | +- Copy the output. |
| 72 | +- Go to GitHub → Logged in as akashdip2001 |
| 73 | +- Go to Settings → SSH and GPG keys → New SSH key |
| 74 | +- Title: Laptop SSH |
| 75 | +- Paste the key → Save. |
| 76 | + |
| 77 | +### ✅ Do same with another account. |
| 78 | + |
| 79 | +--- |
| 80 | + |
| 81 | +## Go to |
| 82 | + |
| 83 | +``` |
| 84 | +C:\Users\akash\.ssh |
| 85 | +``` |
| 86 | +- And create the `config` file with `No` extention. |
| 87 | +- And pest it. |
| 88 | + |
| 89 | +```go |
| 90 | +# Primary GitHub account |
| 91 | +Host github-akashdip |
| 92 | + HostName github.com |
| 93 | + User git |
| 94 | + IdentityFile ~/.ssh/id_rsa_akashdip |
| 95 | + |
| 96 | +# Secondary GitHub account |
| 97 | +Host github-arkadip |
| 98 | + HostName github.com |
| 99 | + User git |
| 100 | + IdentityFile ~/.ssh/id_rsa_arkadip |
| 101 | +``` |
| 102 | + |
| 103 | +<img width="1920" height="1080" alt="Screenshot (113)" src="https://github.com/user-attachments/assets/3c7c08f1-1d89-46f6-a7d5-4ca6277f18d9" /> |
| 104 | + |
| 105 | +--- |
| 106 | + |
| 107 | +# 🔄 Last Step: Change Remote URL in Each Project |
| 108 | + |
| 109 | +## ✅ In IntelliJ (Primary project) |
| 110 | + |
| 111 | +Go to your project folder and run: |
| 112 | + |
| 113 | +```bash |
| 114 | +git remote set-url origin git@github-akashdip:userName/your-repo-name.git |
| 115 | +git config user.name "useName" |
| 116 | +git config user.email "akashdipXXXXXX@google.in" |
| 117 | +``` |
| 118 | + |
| 119 | +## ✅ In VS Code (Secondary project) |
| 120 | + |
| 121 | +Go to your project folder and run: |
| 122 | + |
| 123 | +```bash |
| 124 | +git remote set-url origin git@github-arkadip:UserName/your-repo-name.git |
| 125 | +git config user.name "userName" |
| 126 | +git config user.email "arkadipXXXXX@gmail.com" |
| 127 | +``` |
| 128 | + |
| 129 | +📌 Replace `your-repo-name.git` with the actual repo name. |
| 130 | + |
0 commit comments