Multiple Git user configs
If you already had Git configured, you may not have used your student email. No problem — below are three different ways to solve it. If none of them is enough, you’ll find more ideas on Stack Overflow.
Method 1: Change your GitHub settings
Section titled “Method 1: Change your GitHub settings”The easiest is probably to change git config --global user.email to your student email, and at
the same time
change your primary email on GitHub
to the same address.
git config --global user.email 'en999zz@student.lnu.se'Method 2: Create a local configuration
Section titled “Method 2: Create a local configuration”You can store the email address per repository instead of globally. More cumbersome, but it works.
Note that --global is missing this time.
git config user.email 'en999zz@student.lnu.se'Method 3: Conditional includes
Section titled “Method 3: Conditional includes”If you don’t mind keeping all the course’s repositories as subfolders in a common folder, you can use Git’s conditional includes to automatically use the right user depending on where on the computer you are.
-
Create a main folder for the course’s repositories, for example
schoolin your home directory (~). You can choose another name or location — just remember to adjust the paths in the rest of the steps.mkdir ~/school -
Create a configuration file where the name and email for this folder will be stored:
touch ~/school/.gitconfig -
Open the file in any text editor, for example VS Code:
code ~/school/.gitconfig -
Add the following to the file and save:
[user]name = Ellen Nuemail = en999zz@student.lnu.se -
Open your global
.gitconfig(the same file you set your name and email in under Set up Git):code ~/.gitconfigAdd the following at the bottom of the file and save:
[includeIf "gitdir:~/school/"]path = ~/school/.gitconfig -
Done! All repositories in
school(or any subfolder of it) now use the configuration you set up in~/school/.gitconfig.