Ever need a different git setting per repo?

Maybe you have one git account for work, and one for open source. How do you make sure the right author is used in each repo?

Joel Clermont
Joel Clermont
2023-10-31

Git allows extensive customization, but one of the most common things all git users do is set their name and email address. This is used to identify the author of each commit.

Generally, we set that configuration at a global level. But what if you have multiple git accounts? Maybe you have one git account for work, and one for open source. How do you make sure the right author is used in each repo?

It's important to understand that git configuration is hierarchical. It looks in 3 different places, in a specified order, and the last one wins. First, it checks system settings, then global settings, then local repo settings.

So you can have one default name/email set up in the global ~/.gitconfig file, and then within a specific repo override it with a different name/email by using git config --local user.name "Your Name" and git config --local user.email [email protected].

But maybe you clone a lot of repos and you're concerned you might forget this extra step and accidentally commit with the wrong author? As of git 2.8, you can use the git config --global user.useConfigOnly true config to force you to specify an author for each repo.

Here to help,

Joel

P.S. Pairing with other devs is a great way to pick up interesting workflow tips like this. If you'd like to pair with a Laravel expert on your project, you can set something up on our calendar.

Toss a coin in the jar if you found this helpful.
Want a tip like this in your inbox every weekday? Sign up below 👇🏼

Level up your Laravel skills!

Each 2-minute email has real-world advice you can use.