Git Documentation: Using Multiple Users
Introduction
Managing multiple users in Git can be essential for various reasons, such as handling personal and work projects separately or collaborating on projects with different credentials. This documentation provides a step-by-step guide on how to configure Git to use multiple users efficiently.
Configuring Multiple Users in Git
To manage multiple users in Git, you need to modify the .gitconfig file and set up a credential helper. Here are the steps to achieve this:
Step 1: Modify the .gitconfig File
Add the following block to your .gitconfig file to configure your user details and credential helper:
[user]
name = <username>
email = <userGmail>
[credential]
helper = store
username = <username>Replace <username> and <userGmail> with your actual Git username and email.
For Example:
[user]
name = vatan18
email = [email protected]
[credential]
helper = store
username = vatan18Step 2: Install Git Credential Helper
Git credential helper is a tool that helps you store and manage your Git credentials securely. Follow these steps to install it:
-
On Windows
-
Open the Git Bash terminal.
-
Run the following command to enable the credential helper:
git config --global credential.helper wincred
-
-
On macOS
-
Open the Terminal.
-
Run the following command to enable the credential helper:
git config --global credential.helper osxkeychain
-
-
On Linux
-
Open the Terminal.
-
Run the following command to enable the credential helper:
git config --global credential.helper cache
-
Step 3: Add Credentials to the .git-credentials File
After setting up the credential helper, add your Git credentials to the .git-credentials file. The credentials should be in the following format:
https://<github_username>:<github_token>@github.comReplace <github_username> with your GitHub username and <github_token> with your GitHub personal access token.
Example
Here's an example of what your .gitconfig and .git-credentials files might look like:
.gitconfig
[user]
name = johndoe
email = [email protected]
[credential]
helper = store
username = johndoe.git-credentials
https://johndoe:[email protected]