I have a personal computer that I also use for work. For work, I have to upload files to a large amount of github repos and in order to do so using my work github account, I need to pass git config user.name [USERNAME]
and git config user.email [EMAIL]
in every repo. I have all these repos located within a single parent directory (which is not a repo). Is there any way for me to set the git username and git email for every github repo within this parent directory?

- 769
- 2
- 8
- 18
-
4I guess your best bet would be creating a bash script that iterates over subdirectories and sets name and email for each repo. – Konstantin Jul 29 '17 at 19:14
-
1Why not to set it globally? – phd Jul 29 '17 at 22:31
-
See also [Is it possible to have different Git configuration for different projects?](https://stackoverflow.com/questions/8801729/is-it-possible-to-have-different-git-configuration-for-different-projects). – aruku7230 Oct 21 '22 at 08:58
2 Answers
You could make your parent directory the "superproject" and all repositories submodules of this superproject. Please see Git Submodules
After configuring this you can loop through your submodules as followed:
git submodule foreach git config user.name "User Name"
git submodule foreach git config user.email "user@abc.com"

- 27,428
- 2
- 75
- 95

- 449
- 1
- 5
- 19
If you want the same name for every project then set it globally:
$ git config --global --add user.name "Your name"
$ git config --global --add user.email "your_em@il.com"
If you want to set different name and email for different projects do the following.
Find all .git/config
files and store them in the file:
$ for gitdirr in `find . -type d -name ".git"` ; do echo $gitdirr/config ; done > gitconfigs
Find all git configs containing [user]
section, probably they will have name
and email
set, so you have to change them to the ones you want:
$ grep -li "\[user\]" `cat gitconfigs`
Open the files and check if names are the ones you want, change if not.
Find files which do not contain user section:
$ grep -Li "\[user\]" `cat gitconfigs`
Open each file and add user section with name
and email
keys with values specific for the project:
[user]
name = Your name for the project
email = Your em@il for the project

- 3,202
- 3
- 29
- 33