different git account for subdirectory
1 min read • 19 Feb 2024Views:
If you want to have a specific git account work for a subdirectory, you can make it happen with the help of conditionally including another gitconfig in your root one
Here's how you can do it
- Create a .gitconfig inside your subdirectory, and add your name and email as below
[user]
name = akulsr0
email = akulsr0@gmail.com
Now, you need to include this .gitconfig conditionally inside your root ~/.gitconfig
You can do that by adding following code inside your root git configuration i.e. ~/.gitconfig
[includeIf "gitdir:~/Documents/opensource/**"]
path = ~/Documents/opensource/.gitconfig⏎
- Now, directories inside your subdirectory will have the new git account. You can verify that by running following command in your terminal (inside any folder within your subdirectory)
git config user.email
- Now, for any repository to use new config's email, you can clone it with adding that username in clone url as follows
git clone https://username@github.com/username/repository.git