|
|
# Multiple user configs
|
|
|
If you already have [Git](/git) configured you perhaps didn't use your student email. That's okay, there are multiple ways to solve this.
|
|
|
|
|
|
## Change Github settings
|
|
|
One way is to change your `git config --global user.email` to your student email and [change your primary email on Github](https://help.github.com/en/github/setting-up-and-managing-your-github-user-account/changing-your-primary-email-address) to your student email as well.
|
|
|
|
|
|
```bash
|
|
|
git config --global user.email 'st123id@student.lnu.se'
|
|
|
```
|
|
|
:warning: _Replace `st123id` with your student id._
|
|
|
|
|
|
## 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._
|
|
|
|
|
|
```bash
|
|
|
git config user.email 'st123id@student.lnu.se'
|
|
|
```
|
|
|
:warning: _Replace `st123id` with your student id._
|
|
|
|
|
|
## Conditional includes
|
|
|
If you don't mind keeping all your projects as subfolders in a "School" directory you can use [conditional includes](https://git-scm.com/docs/git-config#_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 user 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.
|
|
|
|
|
|
```bash
|
|
|
mkdir ~/school
|
|
|
```
|
|
|
|
|
|
### Step 2: Create the config file
|
|
|
Here you will store your name and email.
|
|
|
|
|
|
#### Create the file
|
|
|
```bash
|
|
|
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.
|
|
|
```bash
|
|
|
code ~/school/.gitconfig
|
|
|
````
|
|
|
Using a Mac? You need to install the `code` command first. It's quickly done by open the Command Palette (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 an text editor. For this example, I'll continue using Visual Studio Code.
|
|
|
```bash
|
|
|
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`.
|
|
|
|
|
|
## Other solutions
|
|
|
There are many different ways to solve this problem. You can find some ideas [here](https://stackoverflow.com/questions/4220416/can-i-specify-multiple-users-for-myself-in-gitconfig). |
|
|
\ No newline at end of file |