├── .gitconfig ├── .gitconfig-personal ├── .gitconfig-project1 ├── .gitconfig-project2 ├── README.md ├── setup.sh └── structure.png /.gitconfig: -------------------------------------------------------------------------------- 1 | [includeIf "hasconfig:remote.*.url:git@github.com:GITHUB_USERNAME_PLACEHOLDER/**"] 2 | path = ".gitconfig-personal" 3 | 4 | [includeIf "hasconfig:remote.*.url:git@bitbucket.org:project1/**"] 5 | path = ".gitconfig-project1" 6 | 7 | [includeIf "hasconfig:remote.*.url:git@gitlab.com:project2/**"] 8 | path = ".gitconfig-project2" 9 | 10 | [pull] 11 | rebase = true 12 | [fetch] 13 | prune = true 14 | [diff] 15 | colorMoved = zebra 16 | [init] 17 | defaultBranch = main 18 | [rebase] 19 | autoStash = true 20 | 21 | [alias] 22 | co = checkout 23 | br = branch 24 | st = status 25 | lg = log --oneline --graph --all -------------------------------------------------------------------------------- /.gitconfig-personal: -------------------------------------------------------------------------------- 1 | [user] 2 | name = PERSONAL_NAME_PLACEHOLDER 3 | email = you@personal.com 4 | 5 | [core] 6 | sshCommand = "ssh -i ~/.ssh/id_rsa_personal" 7 | -------------------------------------------------------------------------------- /.gitconfig-project1: -------------------------------------------------------------------------------- 1 | [user] 2 | name = PROJECT1_NAME_PLACEHOLDER 3 | email = you@project1.com 4 | 5 | [core] 6 | sshCommand = "ssh -i ~/.ssh/id_rsa_project1" 7 | -------------------------------------------------------------------------------- /.gitconfig-project2: -------------------------------------------------------------------------------- 1 | [user] 2 | name = PROJECT2_NAME_PLACEHOLDER 3 | email = you@project2.com 4 | 5 | [core] 6 | sshCommand = "ssh -i ~/.ssh/id_rsa_project2" 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 🧠 gitmeright 2 | 3 | [![GitHub Repo stars](https://img.shields.io/github/stars/s403o/gitmeright?style=social)](https://github.com/s403o/gitmeright/stargazers) 4 | [![GitHub last commit](https://img.shields.io/github/last-commit/s403o/gitmeright)](https://github.com/s403o/gitmeright/commits/main) 5 | [![GitHub issues](https://img.shields.io/github/issues/s403o/gitmeright)](https://github.com/s403o/gitmeright/issues) 6 | [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) 7 | ![GitHub repo size](https://img.shields.io/github/repo-size/s403o/gitmeright) 8 | ![GitHub forks](https://img.shields.io/github/forks/s403o/gitmeright?style=social) 9 | ![GitHub pull requests](https://img.shields.io/github/issues-pr/s403o/gitmeright) 10 | 11 | **Automatically use the right Git identity per project.** 12 | No more wrong emails, mismatched SSH keys, or accidental commits with your work account on side projects 😅 13 | 14 | `gitmeright` helps you manage multiple Git identities — personal(github), project1 (Bitbucket), and project2 (GitLab) — all from a single, smart `.gitconfig`. 15 | 16 | --- 17 | 18 | ## ✨ What It Does 19 | 20 | ✔️ Automatically switches your Git config based on the remote URL 21 | ✔️ Keeps work, freelance, and personal identities separate 22 | ✔️ Prevents “oops wrong email” moments 23 | ✔️ Adds aliases and fetch/prune tweaks for a smoother experience 24 | ✔️ Works on macOS, Linux, WSL, and beyond 25 | 26 | --- 27 | 28 | ## 🗂️ Folder Structure 29 | 30 | Here’s how it’s organized: 31 | 32 | ![Git config layout tree](structure.png) 33 | 34 | > This diagram shows how `.gitconfig` connects to different profile files and SSH keys based on your project. 35 | 36 | --- 37 | 38 | ## ⚙️ Example of a Main Config: `.gitconfig` 39 | 40 | ```ini 41 | [includeIf "hasconfig:remote.*.url:git@github.com:your-user/**"] 42 | path = ".gitconfig-personal" 43 | 44 | [includeIf "hasconfig:remote.*.url:git@bitbucket.org:project1/**"] 45 | path = ".gitconfig-project1" 46 | 47 | [includeIf "hasconfig:remote.*.url:git@gitlab.com:project2/**"] 48 | path = ".gitconfig-project2" 49 | 50 | [pull] 51 | rebase = true 52 | [fetch] 53 | prune = true 54 | [diff] 55 | colorMoved = zebra 56 | [init] 57 | defaultBranch = main 58 | [rebase] 59 | autoStash = true 60 | 61 | [alias] 62 | co = checkout 63 | br = branch 64 | st = status 65 | lg = log --oneline --graph --all 66 | ``` 67 | 68 | ## 🔧 Example of a Per-Project Config: `.gitconfig-project1` 69 | 70 | ```ini 71 | [user] 72 | name = Your Project1 Name 73 | email = you@project1.com 74 | 75 | [core] 76 | sshCommand = "ssh -i ~/.ssh/id_rsa_project1" 77 | ``` 78 | 79 | ## 🛠 How to Set It Up 80 | 81 | ### Step 1: Clone the Repository 82 | 83 | ```bash 84 | git clone https://github.com/s403o/gitmeright.git && cd gitmeright 85 | ``` 86 | 87 | ### Step 2: Use the One-Line Setup Script 88 | 89 | ```bash 90 | ./setup.sh 91 | ``` 92 | -------------------------------------------------------------------------------- /setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # gitmeright setup script 3 | # author: @s403o 4 | 5 | echo "🎉 Welcome to gitmeright setup!" 6 | 7 | # Step 1: User Input 8 | read -p "🔧 Enter your GitHub username: " GITHUB_USER 9 | read -p "👤 Enter your full name for Personal (GitHub): " NAME_PERSONAL 10 | read -p "📧 Enter email for Personal: " EMAIL_PERSONAL 11 | 12 | read -p "🔧 Enter name for Project 1 (e.g., work): " PROJECT1 13 | read -p "👤 Enter your full name for $PROJECT1: " NAME_PROJECT1 14 | read -p "📧 Enter email for $PROJECT1: " EMAIL_PROJECT1 15 | 16 | read -p "🔧 Enter name for Project 2 (e.g., freelance): " PROJECT2 17 | read -p "👤 Enter your full name for $PROJECT2: " NAME_PROJECT2 18 | read -p "📧 Enter email for $PROJECT2: " EMAIL_PROJECT2 19 | 20 | # Step 2: Copy main .gitconfig 21 | echo "📁 Copying .gitconfig to ~/.gitconfig..." 22 | cp .gitconfig ~/.gitconfig 23 | 24 | # Replace placeholders in ~/.gitconfig 25 | sed -i.bak "s/GITHUB_USERNAME_PLACEHOLDER/$GITHUB_USER/" ~/.gitconfig 26 | sed -i.bak "s/.gitconfig-personal/.gitconfig-personal/" ~/.gitconfig 27 | sed -i.bak "s/project1/$PROJECT1/" ~/.gitconfig 28 | sed -i.bak "s/project2/$PROJECT2/" ~/.gitconfig 29 | rm ~/.gitconfig.bak 30 | 31 | # Step 3: Copy project-specific configs 32 | cp .gitconfig-personal ~/.gitconfig-personal 33 | cp .gitconfig-project1 ~/.gitconfig-$PROJECT1 34 | cp .gitconfig-project2 ~/.gitconfig-$PROJECT2 35 | 36 | # Step 4: Fill in user.name, user.email, sshCommand 37 | 38 | # Personal 39 | sed -i "s/PERSONAL_NAME_PLACEHOLDER/$NAME_PERSONAL/" ~/.gitconfig-personal 40 | sed -i "s/you@personal.com/$EMAIL_PERSONAL/" ~/.gitconfig-personal 41 | sed -i "s/id_rsa_personal/id_rsa_personal/" ~/.gitconfig-personal 42 | 43 | # Project 1 44 | sed -i "s/PROJECT1_NAME_PLACEHOLDER/$NAME_PROJECT1/" ~/.gitconfig-$PROJECT1 45 | sed -i "s/you@project1.com/$EMAIL_PROJECT1/" ~/.gitconfig-$PROJECT1 46 | sed -i "s/id_rsa_project1/id_rsa_$PROJECT1/" ~/.gitconfig-$PROJECT1 47 | 48 | # Project 2 49 | sed -i "s/PROJECT2_NAME_PLACEHOLDER/$NAME_PROJECT2/" ~/.gitconfig-$PROJECT2 50 | sed -i "s/you@project2.com/$EMAIL_PROJECT2/" ~/.gitconfig-$PROJECT2 51 | sed -i "s/id_rsa_project2/id_rsa_$PROJECT2/" ~/.gitconfig-$PROJECT2 52 | 53 | # Step 5: Generate SSH keys if missing 54 | generate_ssh_key() { 55 | local keyname=$1 56 | local email=$2 57 | 58 | if [ ! -f "$HOME/.ssh/$keyname" ]; then 59 | echo "🔐 Generating SSH key: $keyname" 60 | ssh-keygen -t ed25519 -C "$email" -f "$HOME/.ssh/$keyname" -N "" 61 | else 62 | echo "✅ SSH key $keyname already exists. Skipping." 63 | fi 64 | } 65 | 66 | mkdir -p ~/.ssh 67 | 68 | generate_ssh_key "id_rsa_personal" "$EMAIL_PERSONAL" 69 | generate_ssh_key "id_rsa_$PROJECT1" "$EMAIL_PROJECT1" 70 | generate_ssh_key "id_rsa_$PROJECT2" "$EMAIL_PROJECT2" 71 | 72 | # Step 6: Add SSH keys to agent 73 | echo "🚀 Adding keys to SSH agent..." 74 | eval "$(ssh-agent -s)" 75 | ssh-add ~/.ssh/id_rsa_personal 76 | ssh-add ~/.ssh/id_rsa_$PROJECT1 77 | ssh-add ~/.ssh/id_rsa_$PROJECT2 78 | 79 | # Step 7: Done! 80 | echo "" 81 | echo "✅ Setup complete! Git identities are now managed by gitmeright 🔥" 82 | echo "" 83 | echo "Test it with:" 84 | echo " git config user.name" 85 | echo " git config user.email" 86 | echo "" 87 | echo "💡 Tip: Use 'git config --list --show-origin' to see where Git gets its config." 88 | -------------------------------------------------------------------------------- /structure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/s403o/gitmeright/151cf493ef7d6b3e2a0ed2659f6debd64cab93f3/structure.png --------------------------------------------------------------------------------