User:Chlod/Multiple identities

A common situation some developers may have is having to deal with multiple identities for anonymity. For example, someone wishing to help develop features on Gerrit may not wish to have their real name, email, and possibly GPG signing key to be published onto Wikimedia Gerrit repositories. This usually entails the use of scripts, but this worsens developer experience as the effects of configuration changes are usually global (and an extra step prior and subsequent to developing on Wikimedia software).

Luckily, proper configurations can make this experience seamless and scriptless. This page details that setup for developers.

You will need to edit files in your user (or home) directory. The  environment variable on Windows and the   symbol for macOS/Linux points to this folder. Your user folder is one of the following:
 * on Windows
 * on macOS
 * on Linux

SSH
It's advised to use a different SSH identity for Wikimedia Gerrit/GitLab with the one you have for work/real life. Not only does this allow you to set a different passphrase for your Wikimedia keys, but it makes your public key different and thus isolates your real identity from your Wikimedia one.

If you don't have keys for Wikimedia yet, you can generate one with the following commands. This will generate an ED25519 key with the comment "bob@example.com's Wikimedia key" (changeable as needed) under a  folder on your existing   folder.


 * On Windows
 * On macOS/Linux

Next, you'll need to write (or modify) your SSH configuration to automatically use this key for connecting to Wikimedia Gerrit/GitLab. Create (or edit) the  file in your user directory and add the following lines:

You can optionally uncomment the  line to always use   as the user when connecting. You can also uncomment the  line to always use the port 29418 when talking to Gerrit. Both of these are useful for the section below, in case you decide to go with that option.

To test this configuration for Gerrit, run the appropriate command in your terminal: You should see a " " message. If you instead received " " or similar, double-check your configuration to see if you made a mistake.
 * (if you uncommented only the  line)
 * (if you uncommented only the  line)
 * (if you uncommented both  and   lines)
 * (if you uncommented both  and   lines)

To test this configuration for GitLab, run the following command in your terminal: You should see a " " message. If you instead received " " or similar, double-check your configuration to see if you made a mistake.

Git
One of the most common solutions is setting per-repo configurations, but this is a hassle especially if you're making changes to many different MediaWiki repositories. In addition, your Git configuration won't be taken into consideration when cloning repositories, which can cause a global config option (such as ) to be applied when you don't want it to.

Git 2.36 added the new "conditional includes" options for the Git configuration, which allows you to conditionally include a different file for your Git configuration. Through this, you'll be able to set a different Git identity based on either directory (suggested) or remote.

For this part, the Wikimedia-specific configuration will be stored in. You can change this to point to somewhere else for ease of access.

Directory-based Git configuration
This assumes that all of the repositories you will be working on will be cloned under a specific folder on your computer.

Windows is a bit quirky and not like the other OSes, so the process is a bit different.
 * On Windows

Edit (or create) the  file in your user directory. Assuming that your Wikimedia-related projects are in :

If the folder is on another drive, just change the path after.

Edit (or create) the  file in your user directory. Assuming that your Wikimedia-related projects are in :
 * On macOS/Linux

Now, create a  file in your user directory. You can now place your custom configuration here. For example, here's some basic values for Gerrit:

You can also set things such as  or   (for GPG).

Remote-based Git configuration
If your Wikimedia-related projects are scattered across your filesystem, you may opt to do remote-based configuration instead. This method is slightly more complicated, owing to the lack of multiple wildcard expressions when globbing.

Edit (or create) the  file in your user directory. Add the following lines into the file, replacing all instances of  with your UNIX shell name, as usual:

The above catches all possible permutations for the Gerrit and GitLab remotes, to ensure that the configuration still applies even if small parts of the URL change. With the  and   configurations in the  section above, you can have the following instead: But this does make your life harder as you have to be sure to clone the proper repository URL whenever cloning (i.e. remove the port and username from the URL). The above method is more fire-and-forget, despite its size.

Testing
To test this, navigate to a cloned repository using your terminal, and run. If you modified your  in your Wikimedia configuration, it should apply here. You can confirm where the configuration value is being set with  (e.g.  ).

To be extra sure, you can try running the following:

The top commit should show the proper user name and email (if you've changed them). To reset this, use the following (or, if that doesn't work, just re-clone the repository):