Chuck
Posted on November 5, 2019
Cover Photo by Scott Webb on Unsplash
Context
While working on lab assignments for Flatiron School I started noticing a surprise error message when pushing my assignments to GitHub: cannot read username for GitHub
. This post is describing my discoveries, a work around, and an eventual discovery as a postscript at the end.
NOTE: This is not a tutorial on how to set up GIT on your computer, but is a troubleshooting tutorial of my experiences.
My Workflow
So, when I start a new lab my workflow is pretty straight forward:
- Browse to the Learn-co(Flatiron's learning platform) Repo
- Fork the repository to my account.
- Clone the repository to my computer.
Cloning
I currently use JetBrain products to develop, and there is a great browser plugin that adds clone links to my GitHub repositories, interacts with JetBrains Toolbox.
By click on the appropriate icon, I can open the project in Rubymine or Webstorm or any other Jetbrain application. This automatically clone the project and asks if I want to open the application. This has been my workflow.
Error!
Troubleshooting
- So, the first time the surprise error message appeared,
cannot read username for GitHub
, I thought it might be mySSH
setup, since I had recently upgraded my Linux OS. So, I checked:
ssh -T git@github.com
But it returned with a successful message.
- Then I thought it may have been the Learn gem which I use to push completed lessons back to the repo, but it authenticated just fine.
- Then the error happened again in a different repo not connected with
Learn
and after some investigating I realized the issue was not associated with aGitHub
ofLearn
. The problem but that I when cloning via the Jetbrains browser plugin, it was cloning viaHTTPS
instead ofSSH
.
Fix HTTPS credentials
DISCLAIMER: This solution works for my system. I have a single user system not connected to a work network, just a home office. Please investigate the best solution for you and your own security.
Git Credentials
Per the GIT documentation: "Git will sometimes need credentials from the user in order to perform operations; for example, it may need to ask for a username and password in order to access a remote repository over HTTP."
- After reading the documentation, I decided to set up as Git Credentials Store.
- Create:
~/.git-credentials
empty file. - Setup global credentials helper:
git config --global credential.helper store
The first time you push to a https
repository, you will still need to enter your username and password, but after that it will be stored in the file you created in unencrypted text.
If you examine the git-credentials
file the site is saved in the following format: https://user:pass@example.com
.
Postscript
After setting up Git Credentials, I found a setting in the browser plugin to clone using SSH
.
Other Reading
- Using GNOME Keyring as Git Credential Helper
- Stored credentials in 'git credential-osxkeychain'Stackoverflow
Posted on November 5, 2019
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.