Managing multiple GitHub accounts on Windows can be tricky, especially when dealing with credentials. Here's a step-by-step guide to handle this efficiently using Windows Credential Manager and project-specific configurations.
Step 1: Remove Existing GitHub Credentials
Before starting, clear any saved GitHub credentials to avoid conflicts:
- Open Control Panel → Credential Manager.
- Switch to the Windows Credentials tab.
- Look for entries like
git:https://github.com
and remove them.
This ensures a clean slate for adding new credentials.
Step 2: Configure Git Username and Password for a Specific Project
To associate a GitHub account with a specific project:
- Navigate to your project's .git folder (ensure hidden files are visible).
- Open the
config
file in a text editor. - Add the following under the
[remote "origin"]
section:
[remote "origin"]
url = https://your-username:your-personal-access-token@github.com/your-repo-name.git
Replace:
-
your-username
with your GitHub username. -
your-personal-access-token
with your Personal Access Token (PAT). -
your-repo-name
with your repository's path.
- Save the file.
This stores credentials for that specific project and prevents Git from asking for authentication each time.
Step 3: Use Another GitHub Account in a Different Project
For other projects, simply clone or initialize the repository as usual. When you push or pull, Git will prompt you to log in via your browser.
Step 4: Switching Between Accounts
After setting up multiple accounts:
-
First Project: Credentials saved in the
config
file will be used automatically. - Other Projects: Git will prompt you to select or enter credentials. To avoid repeated prompts, repeat Step 2 for each project with the desired account.
Step 5: Removing Project-Specific Credentials
If you want to remove or update credentials for a project:
- Open the
.git/config
file. - Remove or modify the
url
under[remote "origin"]
.
Step 6: Generating a Personal Access Token (PAT)
GitHub now requires a Personal Access Token instead of a password. Here’s how to generate one:
- Go to your GitHub Profile → Settings.
- Navigate to Developer Settings → Personal Access Tokens → Tokens (classic).
- Click Generate New Token and select the required scopes (e.g.,
repo
,workflow
). - Copy the token and use it as the password in Step 2.
Final Notes
- This method ensures smooth switching between multiple GitHub accounts without SSH.
- Be cautious about storing credentials in the URL; only do so for non-sensitive projects.
Top comments (0)