4

I have the following in my .git/config

  1 [core]
  2     repositoryformatversion = 0
  3     filemode = true
  4     bare = false
  5     logallrefupdates = true
  6 [remote "origin"]
  7     url = git@github.com:monajalal/instagram-scraper.git
  8     fetch = +refs/heads/*:refs/remotes/origin/*

When I am trying to push the changes to the master I get this error:

$ git push -u origin master
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 tried these both but still get error:

2150  git remote set-url origin https://github.com/monajalal/instagram-scraper.git
 2154  git remote set-url origin git@github.com:monajalal/instagram-scraper.git


mona@pascal:~/computer_vision/instagram/instagram$ git log
commit e69644389a5c7be65ae6eae14d74065e221600cb
Author: Mona Jalal <jalal@cs.wisc.edu>
Date:   Wed Mar 1 17:48:00 2017 -0600

    scrapy for instagram skeleton
mona@pascal:~/computer_vision/instagram/instagram$ git status
On branch master
nothing to commit, working directory clean


$ uname -a ; lsb_release -a
Linux pascal 3.13.0-62-generic #102-Ubuntu SMP Tue Aug 11 14:29:36 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.5 LTS
Release:    14.04
Codename:   trusty

Please suggest fixes.

Mona Jalal
  • 34,860
  • 64
  • 239
  • 408
  • 3
    **"Permission denied (publickey)"**, Have you added your Public Key (`~/.ssh/id_rsa.pub`) in your GitHub Account ? – Sajib Khan Mar 02 '17 at 00:20

2 Answers2

8

If you did not properly setup your ssh key with GitHub, you can at least try with https (which you mentioned):

git remote set-url origin https://github.com/monajalal/instagram-scraper.git

That will ask for your username (monajalal)/password of your GitHub account.

That will work because you own that repository, meaning you have the right to push.
Make sure you have made a commit locally in order to push.

git add .
git commit -m "new commit"

git push -u origin master

The fact that you might be forced to do a git push -f means the destination (the remote GitHub repo) is not empty but includes commits of its own (typically, a README.md or a LICENSE file)

In that case, it is best, with Git 2.9 or more, to do:

git config --global pull.rebase true
git config --global rebase.autoStash true

Then

git pull

That will replay your local commits on top of those present in (and fetched form) the GitHub repo.

Then a simple git push -u origin master would work. No need to force push your history.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

Possibly not the best solution but considering there was nothing in the repository I had created in github I used the following command and it worked out:

git push -f origin master
Mona Jalal
  • 34,860
  • 64
  • 239
  • 408
  • I could have told you that would you have told me your error message – VonC Mar 02 '17 at 06:34
  • 2
    I have edited my answer to explain why you had to do a push -f. But again, when asking question on Stack Overflow, you cannot just mention "it didn't work". Adding the error message will help us help you. – VonC Mar 02 '17 at 07:00