2

When I try and pull:

error: cannot open .git/FETCH_HEAD: Permission denied

When I try a push or a push -u origin master:

master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:xxxxxxxx/xxxxxxxxxx.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again.  See the 'Note about
-forwards' section of 'git push --help' for details.
tshepang
  • 12,111
  • 21
  • 91
  • 136
LeBlaireau
  • 17,133
  • 33
  • 112
  • 192

2 Answers2

7

Reading through the "man git-push" they mention a "git pull" should be enough to resolve this, but since you're getting "error: cannot open .git/FETCH_HEAD: Permission denied" did you perhaps create the clone of the branch using sudo ? If so your files may not be readable by your user. Double check that the file .git/FETCH_HEAD is readable by your user account.

alex
  • 479,566
  • 201
  • 878
  • 984
David K
  • 692
  • 10
  • 23
3

Your local copy might not be in-sync with the remote hub.

Here is a good guideline when pulling/pushing from/to github repo:

  1. git stash - to make sure your changes are stash and your copy is reverted to the last commit that is in-sync with the remote.
  2. git pull - pull changes from remote
  3. git stash pop - to merge your changes to latest source code
  4. git mergetool - if there are conflicts, you need to do this before the changes are merged.
  5. git commit - to commit your changes in your local repo
  6. git push - to push your changes to remote.
Edwin Bautista
  • 463
  • 3
  • 17