β
Full Setup: Use gh to Push from a Second GitHub Account in VS Code
πΉ 1. β Install GitHub CLI
If not already installed, download and install from:
π https://cli.github.com/
Ensure it works:
gh --version
πΉ 2. π Logout from First GitHub Account (if any)
gh auth logout
Select:
GitHub.com- Confirm
πΉ 3. π Login with Your Second GitHub Account
gh auth login
Choose:
- GitHub.com
- HTTPS
- Login with your browser (select your 2nd account)
πΉ 4. π Set the Remote of Your Repo to Use HTTPS
Inside your project folder:
git remote set-url origin https://github.com/SecondUsername/YourRepo.git
Confirm with:
git remote -v
πΉ 5. π§ Optional: Set Git Identity for This Repo
git config user.name "Second Account Name"
git config user.email "secondemail@example.com"
πΉ 6. π Push to GitHub
git add .
git commit -m "Initial commit"
git push origin main
Since you're authenticated with gh, it will use your 2nd GitHub account.
π To Check Logged-in User Anytime
gh auth status