Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialDoug Hawkinson
Full Stack JavaScript Techdegree Student 25,073 PointsHow do I get out of this jam with git/github?
I am fooling around with an exercise to sharpen my MongoDB skills.
I am not sure how to fix this. The other day I experience an OS corruption on my MacBook Pro. I got the data recovered and the OS (High Sierra) resinstalled OK. I haven't lost any data. However, I am not NOT able to commit and/or push to github. There seems to be something that is corrupted in the process somewhere. Here is the most recent attempt to commit and push after modifying my README.md in this exercise I am doing.
dougs-mbp:07node-todo-api doug5solas$ git add .
dougs-mbp:07node-todo-api doug5solas$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: README.md
dougs-mbp:07node-todo-api doug5solas$ git commit -m "Modified README.md"
[master 3697a3a] Modified README.md
1 file changed, 2 insertions(+), 2 deletions(-)
dougs-mbp:07node-todo-api doug5solas$ git push
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin master
dougs-mbp:07node-todo-api doug5solas$ git push --set-upstream origin master
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I have no idea how to get out of this jam.
3 Answers
Rich Donnellan
Treehouse Moderator 27,696 PointsDid you set up a remote to the repository? git push
only works if you set that up (when on master
).
git remote add origin {url}
Rich Donnellan
Treehouse Moderator 27,696 PointsYour public key isn't recognized by macOS (provided it's already set up). You'll need to add it again:
ssh-add -K ~/.ssh/your-key-name
Or, you might need to set up new keys, add to Github, and then add to your ssh-agent.
-
https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/
- https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/
There is a known issue with macOS that prevents your ssh-agent from "remembering" your keys/passphrases. You will need to modify your ~/.ssh/config
file to automatically load keys into the ssh-agent and store passphrases in your keychain.
Host *
AddKeysToAgent yes
UseKeychain yes
Doug Hawkinson
Full Stack JavaScript Techdegree Student 25,073 PointsI followed everything you said. However, I could not how to modify ~/.ssh/config since I cant find it. What I do find is this:
.ssh
id_rsa
id_rsa.pub
known_hosts
Having done the ssh setup, what is next for getting the push up to github?
Rich Donnellan
Treehouse Moderator 27,696 PointsAhhh. Go ahead and just create the config file at ~/.ssh/
. Add that entry and you should be good there.
Rich Donnellan
Treehouse Moderator 27,696 PointsAfter you add your keys to GitHub and start your ssh-agent, add your id_rsa
to it, you should be able to push as before.
Doug Hawkinson
Full Stack JavaScript Techdegree Student 25,073 PointsRich: I added the config file. It looks like this:
Host *
AddKeysToAgent yes
UseKeychain yes
I tried the following two dummy changes and this is what is happening now:
dougs-mbp:07node-todo-api doug5solas$ git add .
dougs-mbp:07node-todo-api doug5solas$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: LICENSE
new file: playground/mongodb-update.1.js
dougs-mbp:07node-todo-api doug5solas$ git commit -m 'testing commit'
[master a58e089] testing commit
2 files changed, 65 insertions(+)
create mode 100755 LICENSE
create mode 100644 playground/mongodb-update.1.js
dougs-mbp:07node-todo-api doug5solas$ git push
fatal: No configured push destination.
Either specify the URL from the command-line or configure a remote repository using
git remote add <name> <url>
and then push using the remote name
git push <name>
dougs-mbp:07node-todo-api doug5solas$ git status
On branch master
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
deleted: playground/mongodb-update.1.js
no changes added to commit (use "git add" and/or "git commit -a")
dougs-mbp:07node-todo-api doug5solas$ git add .
dougs-mbp:07node-todo-api doug5solas$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
deleted: playground/mongodb-update.1.js
dougs-mbp:07node-todo-api doug5solas$ git commit -m 'test 2'
[master 092b2db] test 2
1 file changed, 44 deletions(-)
delete mode 100644 playground/mongodb-update.1.js
dougs-mbp:07node-todo-api doug5solas$ git push
fatal: No configured push destination.
Either specify the URL from the command-line or configure a remote repository using
git remote add <name> <url>
and then push using the remote name
git push <name>
Something is still not right.
Doug Hawkinson
Full Stack JavaScript Techdegree Student 25,073 PointsDoug Hawkinson
Full Stack JavaScript Techdegree Student 25,073 PointsRich:
I solved the problem by manually copying my files to the repo. I then blew away my local workspace. I cloned the repo from github and started a new local workspace. Everything is in sync now and things are working fine.
Rich Donnellan
Treehouse Moderator 27,696 PointsRich Donnellan
Treehouse Moderator 27,696 PointsYeah. Sometimes it's easier to delete and clone a fresh copy. This automatically sets up the remote for you. Glad you figured it out!