wsdevuid798
wsdevuid798

Reputation: 55

If I set meta-data (username and email) per repo, how does Git know the one to use?

Right now, I don't have a Git repo for the project I am working on and I am about to init one.

I have some global meta-data (--global user.name and --global user.email) for my git commits that I set in the past. However, I would like to set up meta-data that is different from the global (i.e., user.name=userid as opposed to my actual name and user.email=private host issued email as opposed to my own email address) for the repo I am about to create and I was going to do this even before initing the new repo. When I set up additon repos in the future, my intention is for them to use global.

How does Git know that I want it to use the custom setting for the repo I'm about to create. How is this resolved when I have multiple repos that don't use the same info. Say I created additional repos after the one I am about to create. How does Git know that it should use custom meta-data for the repo I am about to create and global setting for the others. Can I have different usernames and email address for each repo?

Upvotes: 0

Views: 64

Answers (1)

Raju
Raju

Reputation: 2509

Git provides three different levels/files to store your configuration data. Below are three levels in order of their precedence.

  • Local: Available for current project and stored in .git/config in the project's directory.
  • Global: Available for all projects for the current user and stored in ~/.gitconfig.
  • System: Available for all the users/projects and stored in /etc/gitconfig.

Local > Global > System

Since you need different config for each project, you can store them in local scope so that they will override the global scope where you already have some config set.

Reference:

Cheers!

Upvotes: 1

Related Questions