In this lesson, you will learn how to set a unique identity for a single project that overrides your global Git configuration.
Why Override Your Identity?
By default, Git uses the global identity you configured earlier (your name and email) for every commit you make across your machine. However, you might encounter a scenario where you are working on a side project that requires a different professional alias or perhaps a personal email address that differs from your primary workplace account. Instead of changing your global settings every time you switch tasks, Git allows you to define "local" configurations that apply only to the specific folder you are working in.
Setting a Local Identity
When you are inside the root folder of a specific repository, you can set a local identity using the --local flag. This tells Git to save these settings inside the hidden .git folder of that specific project rather than in your global machine configuration.
Open your terminal, navigate to your project directory, and run these commands:
git config --local user.name "Your Project Name"
git config --local user.email "project-email@example.com"
Once you run these, every commit made within this specific repository will use these credentials, while the rest of your computer continues to use your global identity.
Verifying Your Settings
You can always confirm which identity is currently active for your project by running the configuration check command without the --local flag:
git config user.email
Git will prioritize the local setting if one exists. If it finds no local setting, it will automatically fall back to your global configuration. This keeps your professional and personal contributions organized without the headache of manual reconfiguration every time you open a new project.
Key Takeaway: Use the --local flag when configuring your user name or email to apply identity settings only to the current repository, ensuring your global settings remain unchanged.