Skip to content

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.

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'

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'

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.

  1. Create a main folder for the course’s repositories, for example school in your home directory (~). You can choose another name or location — just remember to adjust the paths in the rest of the steps.

    mkdir ~/school
  2. Create a configuration file where the name and email for this folder will be stored:

    touch ~/school/.gitconfig
  3. Open the file in any text editor, for example VS Code:

    code ~/school/.gitconfig
  4. Add the following to the file and save:

    [user]
    name = Ellen Nu
    email = en999zz@student.lnu.se
  5. Open your global .gitconfig (the same file you set your name and email in under Set up Git):

    code ~/.gitconfig

    Add the following at the bottom of the file and save:

    [includeIf "gitdir:~/school/"]
    path = ~/school/.gitconfig
  6. Done! All repositories in school (or any subfolder of it) now use the configuration you set up in ~/school/.gitconfig.

CCBY