question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Conditional includes in .gitconfig not supported

See original GitHub issue

Describe the bug

The GitHub Desktop client doesn’t support .gitconfig’s Conditional includes.

I’m using a single machine for both work and private development. Each of those requires a distinct Git user (name and email). I don’t want to configure the Git user for each and every repository individually (as I usually forget to do so and notice it when there’re several commits under a wrong user already). That’s why I’m using the Conditional includes. That allows me to have an individual configuration for a specific directory and all its subdirectories, for example:

  • ~/development/ for personal projects with a personal user name/email
  • ~/work/ for projects I’m working on in my job

My base ~/.gitconfig contains something like the following:

# this is a global configuration valid for the whole machine
[user]
    name = My Private Name With Nickname
    email = private@email

# the following section tells Git to use (actually merge to this config) the config file `~/.gitconfig-work` 
# for all repositories located in the directory `~/work/` and all its subdirectories
[includeIf "gitdir/i:~/work/**"]
    # include the content of `~/.gitconfig-work` here, if it contains any directives which have been already defined, it will overwrite them
    path = ~/.gitconfig-work

The content of ~/.gitconfig-work:

[user]
    name = My Work Name
    email = corporate@email

And that’s it. All repositories under the directory ~/work/ will be using the configuration from the base ~/.gitconfig merged with ~/.gitconfig-work (which overwrites anything already defined in the base config). Repositories located anywhere outside of that directory will be using just the configuration from the base config.

And Git reflects that. When I execute git config user.email under the directory ~/work/ or its subdirectories, it prints the e-mail configured in ~/.gitconfig-work.

The problem is that GitHub Desktop is always showing the configuration from the base config. When I open the Repository menu > Repository settings… and select Git config, the option Use my global Git config is selected and the name and the email from the base config are shown there. And, of course, it’s also used as a commit author.

Version & OS

GitHub 2.7.2 Windows 10 Pro 64-bit

Steps to reproduce the behavior

  1. Create two configuration files as described above, one included in the other one
  2. Create a new repository under the directory you have specified in the includeIf directive (gitdir:...)
  3. Check if the included config is correctly applied by executing git config user.email in your repository
  4. Check the Git config section in the Repository settings… dialog in GitHub Desktop

Expected behavior

GitHub Desktop behaves consistently with the official CLI Git client. Also, for example, SourceTree behaves correctly.

Actual behavior

The Conditional includes are ignored by GitHub Desktop.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
sergiou87commented, Apr 27, 2021

I think it should be easy to do, yeah. Please go ahead and submit a PR if you feel comfortable to do so! I’ll assign the issue to you 😄

Just FYI those values will be read-only, you won’t be able to change them from the app, only see them when you open the Repository settings. We assume that if a user set up such an unusual config structure, they know what they’re doing 😅

1reaction
ferenczycommented, Apr 27, 2021

Thanks for your replies guys!

@sergiou87 You’re right, I have tested it on my machine with the same results. I was afraid that you may be using some Git library that doesn’t support the conditional includes, so it may be complicated to fix, but this looks pretty easy to fix to me. Should I take a look and possibly create a PR? Or am I just too naive? 🙂

Also, those conditional includes are configured for a specific directory so it makes sense to me to read them with the repository configuration rather than the global configuration, i.e. using git config user.email in the repository directory. In such a case, the conditional includes are applied without any special option.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can gitconfig options be set conditionally? - Stack Overflow
No, Git config does not support checks or conditional statements. But your underlying shell probably does, so you can use something like:
Read more >
git-config Documentation - Git
This option requests that git config not canonicalize the retrieved variable. ... condition does not evaluate to true; see "Conditional includes" below.
Read more >
Git Conditional Includes - Edward Thomson
With conditional configuration includes, you have a lot more control over how your Git configuration is applied. You can set up some ...
Read more >
Conditional Git configuration - Jiayu's Blog
gitconfig if the .git directory for the repository you are currently working on is located under ~/work/ . When this happens, the settings...
Read more >
Select The Email For Git Commits Based On The Current ...
... to be signed with my personal email. The solution: conditional includes in my .gitconfig! ... That's not supported, unfortunately.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found