Programming

How do I push to GitHub under a different username

25 September 2026 · 4 min read

How do I push to GitHub under a different username

Collaborating on GitHub projects often involves multiple accounts and permissions. Managing these effectively is crucial for a smooth workflow. One common question developers encounter is: How do I push to GitHub under a different username? This seemingly simple task can sometimes become a source of confusion, especially for those new to Git and GitHub. This guide provides a comprehensive walkthrough of various methods to achieve this, ensuring your contributions are correctly attributed and your workflow remains efficient.

Configuring a Global Username and Email

One straightforward method involves configuring your global Git settings. This is ideal if you primarily use a secondary account. You can set your desired username and email globally using the following commands in your terminal:

git config --global user.name "Your Desired Username"
git config --global user.email "your.email@example.com"

Remember to replace “Your Desired Username” and “your.email@example.com” with your actual credentials. This configuration applies to all your Git repositories unless overridden by local repository settings.

Setting Local Repository Configurations

For more granular control, configure specific repositories with different usernames and emails. Navigate to the repository’s directory in your terminal and use these commands:

git config user.name "Your Desired Username"
git config user.email "your.email@example.com"

This method is useful when working on multiple projects requiring different GitHub accounts without altering your global settings. It provides flexibility and avoids accidental commits under the wrong credentials.

Using the -c flag for One-Time Pushes

If you need a quick, one-time push under a different username, the -c flag offers a convenient solution. This avoids changing your global or local configurations. Use the following command:

git -c user.name="Your Desired Username" -c user.email="your.email@example.com" push origin branch-name

Replace “branch-name” with the branch you are pushing. This approach is particularly helpful for occasional contributions or when testing changes under a different account without permanently altering your settings.

Managing Multiple GitHub Accounts with SSH Keys

For a more robust solution when regularly using multiple GitHub accounts, managing separate SSH keys for each account is recommended. This approach allows GitHub to identify the correct account for each push based on the SSH key used. You can generate a new SSH key for each account and configure them within your SSH agent. This streamlines the process and prevents confusion when working across multiple projects and accounts.

Generating SSH Keys

  1. Use the command ssh-keygen -t ed25519 -C "your.email@example.com" replacing with the email associated with the GitHub account.
  2. Follow the prompts to save the key. Choosing a passphrase is recommended for security.
  3. Add the new SSH key to your SSH agent and to your GitHub account settings.

Troubleshooting Common Issues

Sometimes, even with the correct configurations, you might encounter issues. Ensure your SSH keys are correctly added to your SSH agent and GitHub account settings. Verify the remote URL for your repository points to the correct account and repository. Double-check the username and email configured within your Git settings.

Infographic Placeholder: Visual guide to generating and configuring SSH keys for GitHub.

  • Always double-check your username and email settings before pushing to avoid incorrect attribution.
  • Using SSH keys offers a more secure and streamlined approach for managing multiple GitHub accounts.

Choosing the right method depends on your specific needs and workflow. Whether you opt for global configurations, local repository settings, the -c flag, or SSH keys, understanding these different approaches empowers you to seamlessly contribute to GitHub projects under different usernames. For more detailed information, consult the official Git documentation and GitHub help resources. Learn more about SSH keys on GitHub.

By following these strategies, you can efficiently manage your GitHub contributions, ensure proper attribution, and collaborate effectively across multiple projects and accounts. Streamlining this aspect of your workflow enhances productivity and minimizes potential conflicts. Explore the options presented here and choose the best fit for your development needs. This knowledge empowers you to navigate GitHub’s collaborative environment seamlessly. Remember to prioritize security best practices, especially when handling multiple accounts and sensitive information. Learn more about secure collaboration.

FAQ: What if I accidentally push under the wrong username? Amend the commit using git commit --amend --author="Correct Username <correct.email>"</correct.email> and then force push with git push --force-with-lease. Exercise caution when force pushing.

Git Basics - Working with Remotes

Setting up a Repository

Question & Answer :
A friend and myself are sharing my computer. I’ve made pushes to GitHub using the git bash shell on Windows 7. Now we’re in a different project on that computer and I need her to push to her account. But it keeps trying to use my username and saying I don’t have access to her repository:

$ git push her_github_repository our_branch ERROR: Permission to her_username/repository.git denied to my_username. fatal: The remote end hung up unexpectedly IMPORTANT: *Support for password authentication was removed on August 13, 2021.* 

This worked for me, it will prompt for username and password

git config --local credential.helper "" git push origin master