Multiple Git User Configs
If you already have Git configured you perhaps didn't use your student email. That's okay, there are multiple ways to solve this. Beneath are three different solutions. These should be more than enough but if you don't think any of them will suit you you can find some inspiration here.
1. Change Github settings
Probably the easiest way is to change your git config --global user.email to your student email and change your primary email on Github to your student email as well.
git config --global user.email 'st123id@student.lnu.se'
:warning: Replace st123id with your student id.
2. Create a local config
You can save the email for each school repository. This is a tedious process but it works.
Notice that --global is missing.
git config user.email 'st123id@student.lnu.se'
:warning: Replace st123id with your student id.
3. Conditional includes
If you don't mind keeping all your projects as subfolders in a "school" directory you can use conditional includes to use different users depending on your current folder.
Step 1: Create your main directory
In this example, it will be called school and will be in the current user's home directory (~). But you can call it whatever and place it wherever. Just keep in mind that you have to change the paths. All repositories within this directory will use your school user.
mkdir ~/school
Step 2: Create the config file
Here you will store your name and email.
Create the file
touch ~/school/.gitconfig
Open the file
You can use any text editor you want. If you're using Visual Studio Code you can run the following command to open the file.
code ~/school/.gitconfig
Using a Mac? You need to install the code command first. It's quickly done by open the Command Palette in Visual Studio Code (F1 or ⇧⌘P on Mac) and type shell command to find the Shell Command: Install 'code' command in PATH command. You might need to restart your Terminal for the changes to take effect.
Step 3: Add your information
Add the following to your .gitconfig file and save.
[user]
name = Your Name
email = st123id@student.lnu.se
:warning: Replace st123id with your student id and Your Name with your actual name.
Step 4: Edit your global .gitconfig
Open your global .gitconfig in a text editor. For this example, I'll continue using Visual Studio Code.
code ~/.gitconfig
Add the following at the bottom of the file and save.
[includeIf "gitdir:~/school/"]
path = ~/school/.gitconfig
:warning: Change the path if you chose another name or folder structure. Make sure to keep the last / to include all subfolders.
Step 5: All done!
Now all repositories that are within school or any subfolder will use the configs that you added in ~/school/.gitconfig.