Search code examples
gitgitlab

ssh: Could not resolve hostname git: Name or service not known fatal: Could not read from remote repository


After I switched from HTTPS to SSH for my repo then I received this error when pushing to origin master:

ssh: Could not resolve hostname git: Name or service not known
fatal: Could not read from remote repository.

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

I also add my ssh in the gitlab. What should I do?


Solution

  • I was getting the same error.

    This error typically occurs when there is an issue with the SSH configuration or the Git remote repository's hostname cannot be resolved.

    Here, you can check your remote by running:

    git remote -v
    

    There are few reasons why this error occurs:

    • Incorrect Hostname
    • SSH Configuration
    • Network Connection
    • DNS Resolution
    • Firewall or Proxy

    Typically, you can solve this by Change the [remote "origin"] URL value in .gitconfig or .config/git/config file

    Previously:

    https://[email protected]:userName/repo.git
    

    OR

    ssh://[email protected]:userName/repo.git
    

    New:

    [email protected]:userName/repo.git