How to Stop Git Always Asking for Username and Password When Using HTTPS
If Git is always asking you for your username and password when pushing or pulling your code from a GitHub repository, This is a common problem if you use HTTPS clone URL for cloning the repository.
Let's see how to solve this!
https:// clone URLs are available on all public and private repositories. These URLs work everywhere, even if you are behind a firewall or proxy.
Cloning your GitHub Repository Using Https
If you have cloned your repository with HTTPS using your command-line interface, you’ll be prompted for your GitHub username and password.
Why Git Keeps Prompting you for Username and Password
Using HTTPS remote URL is useful if you need to work through strict firewalls and proxies but this also means that you'll get prompted for your GitHub username and password each time you pull or push your code to your repository.
Fixing Git Always Asking for Login Credentials
Fortunately, if you want to stop Git from always asking you for the login credentials of your GitHub repository this can be easily done in two ways:
Using SSH instead of HTTPS
You can update the origin remote using SSH instead of HTTPS:
git remote set-url origin [email protected]:username/your-repo.git
Configure Git to Store your Password and Username
Here’s how you can make Git store the username and password:
git config --global credential.helper store
Next, save the username and password for a session:
git config --global credential.helper cache
We have seen how we can configure Git to stop asking for the username and password when pushing or pulling code from a GitHub repository cloned via HTTPS.
- Author: Ahmed Bouchefra Follow @ahmedbouchefra
✋If you have any questions about this article, ask them in our GitHub Discussions 👈 community. You can also
❤️ Like our page and subscribe to our feed for updates!
Find a list of emojis to copy and paste