Customize git for all projects in a directory
source link: https://alysivji.github.io/multiple-gitconfig-files.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Siv Scripts
Solving Problems Using Code
Yesterday I gave an abridged version of my Data Science Workflows using Docker Containers talk at my employer's Biweekly Engineering Lunch session.
It had been a minute since I last gave this talk so I ran through the examples to make sure everything worked. Having all my examples containerized is a bit of a cheat code, but I did modify a couple of Dockerfile
s to make the demo function. Pushing my changes back to GitHub required me to change my local git repo config:
git config user.name "Aly Sivji" git config user.email "[email protected]"
This is great, but it only works for that one project. And what if I forgot to change this setting?
I decided to overengineer this solution by creating a .gitconfig
that only applies in certain folders. This post documents how to enable multiple .gitconfig
files to control how Git looks and operates in different directories.
Git Config
Git comes with a tool called git config that lets you get and set configuration variables that control all aspects of how Git looks and operates.
First, a quick review: Git uses a series of configuration files to determine non-default behavior that you may want. The first place Git looks for these values is in the system-wide /etc/gitconfig file, which contains settings that are applied to every user on the system and all of their repositories. If you pass the option --system to git config, it reads and writes from this file specifically.
The next place Git looks is the ~/.gitconfig (or ~/.config/git/config) file, which is specific to each user. You can make Git read and write to this file by passing the --global option.
Process
Let's say that we want to have all folders inside of ~/siv-dev/client-work
to have a different Name and Email in the commit logs.
Create a .gitconfig
File
This configuration file will contain settings we want to apply to all subdirectories. Create the following files and save to ~/siv-dev/client-world/.gitconfig
[user] name = Aly Sivji email = [email protected]
Update Global .gitconfig
We will need to add the following lines to our global ~/.gitconfig
:
[includeIf "gitdir:~/siv-dev/client-work/"] path = ~/siv-dev/client-work/.gitconfig
That's it. Now all repos inside of ~/siv-dev/client-work/
will use the custom .gitconfig
file.
Happy Gitting!
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK