The situation is as follows:
Per domain, I want to use a different email address as part of author/committer information. That is, I want my private address to be listed in my free-time projects and my company address in my professional ones.
git config
knows 3 scopes: repository, global and system-wide. What I basically need is a 4th scope between repository and global, representing a group of repositories (or simply a directory in the file system).
It seems like git config
doesn't allow that. Of course I could set the email address per repository, but I want to avoid this manual step every time I set up or clone a repository. One option would be to write a script that wraps git init/clone
and git config
, are there other ideas?
With Git, using multiple repositories is the only way to work efficiently. This enables each team to work independently, and do their work faster. You can also make sure that developers only have access to the repositories they need access to (thus making Git more secure.)
Simply use the command line, cd into the root of your Git repo, and run git config, without the --system and the --global flags, which are for configuring your machine and user Git settings, respectively: Your other option is to edit the repo config file directly.
1. First clone your project from one of these repositories like this: 2. Clone the repository from Github: 3. Open the folder with the cloned project: 4. Now we will manually edit Git repository ‘s configuration file where we will add the second repository as a new remote source. Open .git/config file.
Setup Git with Multiple Configs 1 Move GitHub Clones to New Folder. Now I needed two separate folders. ... 2 Setup Context Specific Git Config. The includeIf allows you to do conditional configuration logic. ... 3 Setup Environment Specific Git-hooks. Configuration is only as good as the verification for it. ... 4 Conclusion. ...
The idea is to segregate the repos on your machine into multiple directories by separating the profiles you want, and then define a .gitconfig file per profile. Organize the projects that you are working on into separate folders by the profiles you want to work with. For example let's say there are two Git profiles you are working with.
based on https://stackoverflow.com/a/44036640/2377961 i think I found a way how it could work.
first you create different config files for your "custom-scopes" (e.g. professional, freetime, ect.) and add your desired user-config for each scope
# ~/all-projects.gitconfig
[user]
name = TheOperator
.
# ~/professional.gitconfig
[user]
email = [email protected]
.
# ~/freetime.gitconfig
[user]
email = [email protected]
than you add lines like this in your standard gitconfig:
# ~/.gitconfig
[include]
path = all-projects.gitconfig
[includeIf "gitdir/i:c:/work/"]
path = professional.gitconfig
[includeIf "gitdir/i:c:/freetime/"]
path = freetime.gitconfig
The directories after "gitdir/i" should match the parents directory of your project groups. In my example you should store your git-repos for freetime-domains e.g. "c:/freetime/my-freetime.domain/.git"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With