Simplify Your Workflow: Switching Git Profiles Automatically by Folder

CK CK 3788 
Created at  
760 0 0

You can set up different Git profiles (name/email) per folder using Git’s config hierarchy. Git supports three levels of config:

  • System (--system): applies to all users on the machine.
  • Global (--global): applies to your user account everywhere.
  • Local (--local): applies only to a specific repo (this overrides global/system).

Since you want three different folders (projects) to have their own profiles, you’ll use local config inside each repo.

Simplify Your Workflow: Switching Git Profiles Automatically by Folder

 

Option 1 – Set local config in each repo

In each repo’s folder, run:

cd /path/to/repo1
git config user.name "Alice Work"
git config user.email "alice@work.com"

cd /path/to/repo2
git config user.name "Alice Personal"
git config user.email "alice@gmail.com"

cd /path/to/repo3
git config user.name "Alice OpenSource"
git config user.email "alice@opensource.org" 

These settings are stored in .git/config inside each repo. They override your global profile.

 

Option 2 – Use directory-based config (includeIf)

1. Open your global git config

git config --global --edit

This opens ~/.gitconfig in your editor.

 

2. Add directory-based rules

Inside ~/.gitconfig, add something like this:

[user]
    name = Alice Default
    email = alice@default.com

[includeIf "gitdir:~/work/"]
    path = ~/.gitconfig-work

[includeIf "gitdir:~/personal/"]
    path = ~/.gitconfig-personal

[includeIf "gitdir:~/oss/"]
    path = ~/.gitconfig-oss

gitdir:~/work/ means “any repo inside ~/work/”.

 

3. Create separate config files

Now create each file with its profile.

~/.gitconfig-work

[user]
    name = Alice Work
    email = alice@work.com

~/.gitconfig-personal

[user]
    name = Alice Personal
    email = alice@gmail.com

~/.gitconfig-oss

[user]
    name = Alice OpenSource
    email = alice@opensource.org

 

4. Verify settings

Go into any repo and run:

git config user.name
git config user.email

It should show the correct profile depending on the folder.

 

Tips:

  • Paths must end with a slash (/) to match a folder and all its subfolders.
  • If your repos are nested deeper (e.g. ~/work/projects/foo), it still works.
  • If you want to match a single repo only, use gitdir:~/work/myrepo/.git instead.
Tags git git config git profile includeIf Facebook X
Comments 0
Similar posts
  1. Viewing Git Graph in ASCII
    600
  1. How Rogue Web Scrapers Are Stealing My Content and Destroying My Server
    170
  2. System Requirements and Architecture: Intelligent Priority-Based Scheduler
    176
  3. Messaging Platform with Limited TPS based on the vendor
    204
  4. Redis vs Memcached: Why Enterprise Tech Giants Choose Redis
    261
  5. ETL vs ELT what makes the differeence? Why MLOps leverage ELT?
    202
  6. Arm Kernel DNNs: Powering Efficient AI at the Edge
    230
  7. Cloud-Native Capital Markets: Architecture, Compliance, and Innovation
    218
  8. Add New Address to gmail without SMTP (forwarding-only-address)
    1,701
  9. Registering an App on the Google Play Store
    1,481
  10. AGENT.md: AI's Blueprint for Robust Software and Vibe Coding
    563
  11. Tailscale: Zero-Config Remote Access to Your Home PC, Firewall-Free
    539
  12. Markdown's Visual Revolution: Meet Mermaid.js
    417
  13. Vibe Coding: Harmonizing Intent with AI Productivity
    505
  14. How do I change the theme for code block in Confluence Cloud?
    1,397
  15. FIPS - Federal Information Processing Standards
    1,406
  16. How to Control External Monitor Brightness, Sound Volume on a Mac with MonitorControl (Even Over HDMI)
    2,410
  17. Building Multilingual Applications with i18n
    1,208
  18. Kiro versus Cursor AI - Spec-Driven? or Chat-Driven?
    408
  19. How to use multiple RSA (SSH) keys for GitHub
    337
  20. Key Metrics Track to Ensure the Health and Performance of a Distributed System
    181
  21. REST API Vs. GraphQL
    414
  22. Project Libre similar to MS Project
    533
  23. Learning about Firestore: Architecture, Pros, Cons, and Real-World Deployments
    173
  24. Building Privacy-First Infrastructure: Network Isolation + Zero Trust for GDPR Compliance
    298
  25. Why supabase is not safe for the Fintech project?
    862
  26. The Ultimate Data Engineering Roadmap
    1,084
  27. Nine Types of Testing while we develop APIs
    519
  28. Apache Kafka - a distributed, fault-tolerant, high-throughput streaming platform
    618
  29. Comprehensive Software Development Flow : How Companies Ship Code To Production
    2,334
  30. DeepSeek v3 offers of ChatGPT's performance at 1/10 the price!
    639
Recently updated
  1. Google OAuth Token Expiration: Causes and Solutions
    31
  2. Why 100% SEO Guarantees Better User Engagement and How to Achieve It in Your Service
    57
  3. Why SPF and DKIM Are Essential for Linux Email Servers?
    51
  4. How do I create animated background for Google Meet?
    23,251
  5. MaxMind GeoLite2 vs. DB-IP Lite vs. ip-api.com: Choosing the Right Free IP Geolocation Solution
    273
  6. Meet Valkey: Why Redis Changed Its License, Why Valkey is Better, and How to Use It as a Drop-in Replacement
    104
  7. Array of arguments passed to script in PHP
    99
  8. Invalid Auction Storms in Ad Tech
    107
  9. Building MRC-Compliant Instrumentation in Ad Tech: Implementation Steps and Key Challenges
    209
  10. The Two Clocks of Ad Server Architecture
    78
  11. Frequency Cap Architecture Overview
    527
  12. Collecting Proof-of-Play from 100,000 Screens
    153
  13. Vector Search in Relational Databases (RDBs): Trends & Usage Environments
    303
  14. What is RedisVL?
    116
  15. Designing a Skill Registry Architecture: Minimize Token Usage and Maximize AI Performance
    247
  16. TPU & GPU Cluster Management Tools
    258
  17. The Concept of Scaffolding in AI Agents
    245
  18. Beyond Static Pipelines: Architecting LLM Multi-Agent Systems for Autonomous Workflow Orchestration
    598
  19. AI-DLC vs. AI-SDLC: Model-Centric vs. System-Centric AI Development
    269
  20. Fine-Tuning Open-Weight LLMs: Training, Licensing, and Deploying Custom Models with Ollama
    355
  21. Inside the Next-Generation Streaming Architecture: Ultra-Low Latency, SGAI, and AI Codecs
    207
  22. Machine Learning: Training vs. Ranking
    230
  23. The Continuous Learning Machine: Designing a Loop That Actually Turns
    229
  24. The Next-Gen Low-Latency Standards: LL-HLS & MoQ
    204
  25. Designing a Data Curation System Around a Vector Database
    230
  26. Extracting Context from Live Video: The Architecture Got Simpler When We Stopped Building Features
    263
  27. The New Ad Stack Behind Live Sports Streaming: Inside SGAI, EABN, and the Standards Race to Fix Live Monetization
    674
  28. Designing MLOps Architectures to Handle Seasonal Data Drift in EV Fleet Models
    201
  29. From 15 to 40+ FPS: Accelerating PyTorch Object Detection on Automotive ECUs
    233
  30. Understanding Data Lineage
    272