Search code examples
gitgit-submodules

Local git config in git submodule


My repository structure:

repo_a
└── repo_b
    └── .gitconfig

repo_b is a submodule.
.gitconfig:

[alias]
    b = branch

How can I add the path of .gitconfig such that only repo_b can use it?

Expected output:

$ cd repo_a
$ git b
git: 'b' is not a git command. See 'git --help'.
$ cd repo_b
$ git b
* master

Edit #1:

The answers from @jthill and @bk2204 are good.
They describe how to access the config file for the submodule using:

git rev-parse --git-path config

I want to specify what I want.
I want the changes in the .gitconfig file in repo_b to be tracked by git. Such that when cloning only repo_b I would also have access to the same .gitconfig.
The solution from @jthill does seem possible. However, it does also seem quite error-prone, and I would have to add a hook for every single change in git that might change the .gitconfig. Such as git pull, git checkout, git merge.

Thus my question would have 2 parts:

  1. How can I both track changes for repo/.gitconfig and use it as a local config file?
  2. How can I implement said functionality for both a normal repo and within a submodule?

Solution

  • I did not implement this feature because of security concerns.

    I decided to use a separate configuration file in JSON and store the values I needed there.
    Thus I could parse the config file when needed instead of using git.