GIT - Errors

git pull fails : fatal: '/path/to/some/dir' does not appear to be a git repository

Situation :

git pull [options]
fatal: '/path/to/some/directory' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Details :

  1. you have either explicitly typed it or configured Git so that it receives a command such as :
    git pull someRemote someBranch
  2. based on the remote name, Git infers a URL to pull from :
    • git remote -v | grep -E '^someRemote'
    • git remote get-url someRemote
  3. when that URL is not available, you get the error message above

Solution :

Several reasons may cause this error :

git clone fails : fatal: unable to access 'https://github.com/.../....git/': gnutls_handshake() failed: An unexpected TLS packet was received.

  1. Run :
    [ -n "$http_proxy" ] && git config --global http.proxy "$http_proxy"; [ -n "$https_proxy" ] && git config --global https.proxy "$https_proxy"
    to append to ~/.gitconfig :
    [http]
            proxy = http://12.34.56.78:1234
    [https]
            proxy = https://12.34.56.78:1234
  2. retry the git clone

patch fragment without header + Your edited hunk does not apply during git add --interactive

Situation :

Full message :
Stage this hunk [y,n,q,a,d,K,J,g,/,e,?]? e
error: patch fragment without header at line 51: @@ -129,5 +145,7 @@
Your edited hunk does not apply. Edit again (saying "no" discards!) [y/n]?

Details :

This answer has some interesting information about editing hunks (but not the answer to the current issue, though )

Solution :

Possible cause Solution
a Git bug (sources: 1, 2) Don't split + edit hunks, edit them directly.
My editor (Emacs) is configured to delete trailing whitespace before saving,
which deletes context lines from the patch (these lines contain only a single SPACE character)
(source)
  • disable this Emacs hook
  • use a different text editor :
  • in Emacs configuration file, replace (source) :
    (add-hook 'before-save-hook 'delete-trailing-whitespace)
    with :
    (add-hook 'before-save-hook
    	(lambda ()
    		(unless (eq major-mode 'diff-mode)
    			(delete-trailing-whitespace))))

Git command fails : fatal: unable to access 'https://git.domain.tld/path/to/myRepository/': server certificate verification failed.

Situation :

git clone https://git.domain.tld/path/to/myRepository/
Cloning into 'myRepository'...
fatal: unable to access 'https://git.domain.tld/path/to/myRepository/': server certificate verification failed. CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none

Solution :

GIT_SSL_NO_VERIFY=true git clone https://git.domain.tld/path/to/myRepository/
  • This applies to any Git command, not only git clone.
  • To make this permanent :
    git config --global http.sslVerify false
    This does the job but the --global flag disables server certificate validation for all repositories, making you vulnerable to a man-in-the-middle attack. Instead (source) :
    1. jump to the root directory of your Git repository :
    2. disable server certificate validation for this repository only :
      git config http.sslVerify false

git push origin master ends up with remote: error: refusing to update checked out branch: refs/heads/master

When trying to git push from a remote back to the origin, I get this error message :
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error:
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.
remote: error:
remote: error: To squelch this message and still keep the default behavior, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To /path/to/my/repo/.git
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to '/path/to/my/repo/.git'

As said by this error message : you just can NOT push to a non-bare Git repository (details).

Some solutions are still available :

Your branch is ahead of 'origin/master' by n commits. after successfully pulling from origin to remote

Situation :

Working with local and remote branches, when sitting on a remote branch and after pulling from origin to remote, git status says :
Your branch is ahead of 'origin/master' by n commits.
(n being the number of commits I made on the origin).

Details :

On the remote, the commits I made on the origin are there. It looks like only the count of commits is wrong.

Solution :

On the remote branch, run :
git fetch origin

git pull complains Your local changes to 'myFile' would be overwritten by merge. Aborting.

This error message is fairly explicit. To fix this :
  1. git stash : save your work in progress
  2. git pull -f : get updates from the repository
  3. git stash pop : apply the local changes on top of the update