Reference: GitHub article
-
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.
-
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.
-
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.
-
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 trueNote: This command differs from the one provided in some GitHub instructions, which may cause errors. The provided command ensures proper configuration without errors.
-
Navigate to Your Repository:
- Open your terminal or command prompt and navigate to your specific repository directory:
cd /path/to/your/repository -
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.
-
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.
-
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.
- 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.
- Global Git settings (