DEV Community

Cover image for The Hidden Risks of Global Git Configurations and How to Avoid Them

The Hidden Risks of Global Git Configurations and How to Avoid Them

Code of Relevancy on February 06, 2023

I am sharing my personal experience through this article. When working with Git, it's important to properly configure your user name and email to ...
Collapse
 
cappe987 profile image
Casper

This article is wrong on several points. You say that global config is per-user (which it is), then proceed to say it causes problems if there are multiple users on the system. The only time that could be problematic is if everyone uses the same account, which is already a mistake if that's the case. Global configs are completely safe and usually the recommended method.

I never use local config, but if anything wouldn't that one cause problems with multiple users? I would assume that local overrides global. That would be problematic if multiple users shared the same directory on one system.

I have never heard of system config before and I wouldn't recommend using it. That could definitely cause problems on a multi-user system. System-wide account configs are a bad idea.

Realistically though, are there any useful scenarios where you will share git directories with people? It would cause all kinds of problems if people tried to work on it at the same time. I often use remote multi-user systems, but everyone has their own home folder where they make their own clones of the repos. Even if realistically only one will use it at a time, you don't want to mess with other people's work.

If you happen to have the need for multiple accounts, such as a work account and personal account you can use the includeIf statement.

[includeIf "gitdir: ~/work"]
    path = ~/work/.gitconfig-work
Enter fullscreen mode Exit fullscreen mode

This allows you to have a specific git config that overrides your main config for all repos inside that directory. It's a one-time setup and you only need to remember to clone it into the right directory.

And as a final note, you probably won't push by accident either. Ssh keys are also stored per-user. And if you don't have an ssh key you have a password, which only you should know.

Collapse
 
codeofrelevancy profile image
Code of Relevancy

Thank you sir for bringing this to my attention. I appreciate your valuable feedback and insights on Git configs..

Yes, you are correct that the global Git config is per-user and is typically the recommended method. But the only situation where it may cause issues is when multiple users share the same account, which is not a recommended. I apologize for any confusion my article may have caused.

I would like to share my personal experience regarding this issue. 5 years ago, as a beginner in a private company, I had a similar experience. I was assigned to continue a project that was previously worked on by another developer, and both projects were on the same machine, under the same user account. I forgot to change the Git configs for the new project and ended up pushing changes with the wrong author information. Sad to say, this resulted in losing a client for the company..

I double checks the Git configs before pushing changes to avoid such incidents. That experience taught me the importance of using local Git configs instead of global ones. After that, I always use local configs, even on my personal laptop, as I work with multiple Git accounts. When using the git commit command, the system prompts us to set the user name and email for the current project if they have not been set globally. That's what I want.

Thanks again for your valuable comments and I hope my response clarifies any confusion..

Collapse
 
cappe987 profile image
Casper

Ok I see, that makes sense. That company already made the mistake of giving you his account, so it's not really your mistake.

Collapse
 
jmau111 profile image
jmau111 🦄 • Edited

Global level configs are user-specific.

It's the system config (--system) that should be handled more carefully, as it applies to all users and all folders on a operating system.

It's important to set global configs like the pull/prune strategy, default branch, merge tool, core editor, or helpful aliases.

There's no hidden risk. Always use git log before pushing anything to a remote repo to ensure everything is set recorded correctly.

Collapse
 
codeofrelevancy profile image
Code of Relevancy

Thank you sir. I appreciate your valuable feedback..

Collapse
 
smsp profile image
Sobhan Mowlaei

Nice Post. Thank you for noting this risks.

Collapse
 
codeofrelevancy profile image
Code of Relevancy

Thanks for reading..