I have been using git for a few years now, but not studying
it in depth … until now.
Here is my current git issue I am working through. I have some repositories from my job I am
working from. I set up my user.name and
user.email in my ~/.gitconfig file (the global scope). Which is fine and dandy, and working
well. But now I have some personal
repositories that are re-using the same user.email and user.name from the
global scope. I want them to use a
different name and email, but only in these repositories.
Atlassian has a good post on the gitconfig file scope at https://www.atlassian.com/git/tutorial/git-basics#!config
[1]
The first git config file "system
wide"
Before I started this section I temporarily moved the
"global" gitconfig file at ~/.gitconfig file to ~/.gitconfig-BACK.
> mv ~/.gitconfig ~/.gitconfig-BACK
|
Now if I run the following command
> git config user.name
|
I get back nothing
To set user.name in the system wide git config file run the following
command
> git config --system user.name "Patrick
Bailey"
|
Now if I run the following command
> git config user.name
|
I get back
The actual system wide gitconfig file is located at
$(prefix)/etc/gitconfig
|
In cygwin this is located at
/usr/local/etc/gitconfig
|
The second config file "global"
The global gitconfig file, can be thought of as your
personal gitconfig file. It overrides
the global gitconfig file, if it has a variable that is in the global gitconfig
file.
Before I do anything, if I run
> git config user.name
|
I get back (from the system wide gitconfig)
To set user.name in the global gitconfig file run the
following command
> git config --global user.name "Patrick
Test"
|
Now if I run the following command
> git config user.name
|
I get back
The global gitconfig is used before the system wide
gitconfig.
The actual global gitconfig file is located at
~/.gitconfig
|
In cygwin this is located at
/home/patman/.gitconfig
|
The third config file "Repository Specific"
This is a repository specific gitconfig file. And when I say repository specific I mean
repository specific! I, unfortunately,
still think in subversion. So when I saw
"Repository Specific" gitconfig file I thought this file would be
shared when you push/pull to a remote repository. It is not, when you clone a repository a
generic "Repository Specific" gitconfig file is made, but it's not
something that is stored in the repository.
With that in mind this is the file I personally need to
change in my local repositories to solve my personal git problem.
To set user.name in the "Repository Specific"
gitconfig file run the following command
> git config user.name "Patrick Specific"
|
Now if I run the following command
> git config user.name
|
I get back
The "Repository Specific" overrides the global
config file.
The actual "Repository Specific" gitconfig file is
located at
.git/config
|
In each repository.
Here is a simple image to show which scope is used when git
is looking for a variable.
One last thing
Alexander Yancharuk in a posting at http://stackoverflow.com/questions/18329621/storing-git-config-as-part-of-the-repository
[2] suggested a fourth type of gitconfig file,
"custom".
"custom".
He suggest placing a .gitconfig file in your repository, as
part of your repository. This file would
be copied when cloned, much like the .gitignore.
But if that is all you do the file will not be used. He suggest including a path to this file in
one of the other three gitconfig file.
I am still too new to git to see what advantages this would
have with sharing variables with your team.
But I thought I would make note of it here just in case.
References
[1] Atlassian git
basics
Visited 8/2014
[2] Storing git
config as part of the repository
Visited 8/2014
No comments:
Post a Comment