Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save braxton-bell/4fb19c2b7f7dd87e10bdd827da834235 to your computer and use it in GitHub Desktop.

Select an option

Save braxton-bell/4fb19c2b7f7dd87e10bdd827da834235 to your computer and use it in GitHub Desktop.
This guide provides step-by-step instructions on how to use multiple Git accounts on the same device using HTTPS with Personal Access Tokens. It includes detailed steps on creating a Personal Access Token on GitHub, configuring Git on Windows to manage credentials, and setting specific usernames and emails for different repositories to avoid con…

How-To: Use Multiple Git Accounts on the Same Device

Using HTTPS with Personal Access Token

Reference: GitHub article


1. Create a Personal Access Token on GitHub

  1. Navigate to GitHub Personal Access Tokens:

    • Use the following link to create a global access token: New Personal Access Token (Classic).
    • The link to access Personal Access Token configuration is found under Settings > Developer Tools on your GitHub account.
  2. Generate the Token:

    • Set the token expiration time to 90 days for enhanced security and easier management.
    • Store the generated token securely in a password manager like Bitwarden. This ensures that you can retrieve and use it safely without exposing it to unauthorized access.

2. Configure Git on Windows

  1. Erase Existing Credentials:

    • Before configuring new credentials, it's important to clear any existing credentials to prevent conflicts:
    echo "protocol=https`nhost=github.com" | git credential-manager erase

    This command removes the stored credentials for GitHub from the credential manager.

  2. Configure Git to Cache Credentials for the Full Remote URL:

    • Setting Git to use the full remote URL ensures that credentials are cached specifically for each URL:
    git config --global credential.https://github.com.useHttpPath true

    Note: This command differs from the one provided in some GitHub instructions, which may cause errors. The provided command ensures proper configuration without errors.


3. Verify and Set Username and Email for a Git Repository

  1. Navigate to Your Repository:

    • Open your terminal or command prompt and navigate to your specific repository directory:
    cd /path/to/your/repository
  2. Verify the Current Username and Email:

    • It's important to check the current configuration to understand what is set before making changes:
    git config user.name
    git config user.email

    This command will show the username and email currently configured for the repository.

  3. Set the Username and Email for the Specific Repository:

    • Setting a specific username and email for a repository helps differentiate between different Git accounts:
    git config user.name "user-name"
    git config user.email "123456789+user-namel@users.noreply.github.com"

    Note: Using a "noreply" email address helps protect your privacy when contributing to public repositories. You can verify your email settings on GitHub here: GitHub Email Settings.

  4. Verify the Changes:

    • After setting the new username and email, verify the changes to ensure they were applied correctly:
    git config user.name
    git config user.email

    Ensure the output matches the username and email you have set.


Additional Information

  • Impact of "Global" Git Settings:
    • Global Git settings (--global) apply to all repositories on your machine unless overridden by repository-specific settings. This means that when you create a new repository, it will inherit the global username and email settings unless you explicitly set different values for that repository.
    • To avoid conflicts and ensure the correct identity is used for each repository, always verify and set the repository-specific username and email as needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment