12

I'm having a problem with my Git account. Every time I execute git push, I get the following error:

Git push error

I discovered that I'm working with an SSH URL:

SSH URL

I tried switching back to an HTTPS URL using the following commands:

git config --global url.https://github.com/.insteadOf git://github.com/
git config --global url."https://".insteadOf git://

However, it doesn't seem to change anything: example

I tried many options that I thought were solutions such as manually configuration of config file but nothing works.

ylluminate
  • 12,102
  • 17
  • 78
  • 152
Ahlem Tbini
  • 131
  • 1
  • 1
  • 3

5 Answers5

52

This error occurred because your git port is restricted.
So you can get it fixed with the following command:

git config --global url.https://github.com/.insteadOf git://github.com/

By doing this globally it will also repair other issues where perhaps old repositories or other scenarios may be using git instead of https when the git:// port/protocol may not be functional now vs earlier.

Please upvote if it worked for you!
Thank you.

ylluminate
  • 12,102
  • 17
  • 78
  • 152
Amar Singh
  • 620
  • 3
  • 7
  • Very helpful succinct answer, thank you. In my case I was having an odd issue with old `Sublime Text 3` packages failing to update. It turns out that when they were installed they used the `git://` protocol vs `https://` and now no longer update and cause various hangs and peculiar problems with Sublime Text. – ylluminate Apr 01 '23 at 21:36
4

To use git with ssh, a different url syntax is needed, with git@<url> as url. According to your screenshot, the url should most likely look like this

git@github.com:ahlemtbini/blog_web.git

You can change it with the following command

git remote set-url origin git@github.com:ahlemtbini/blog_web.git

If you are using github, i recommend you to always use the url's listed under the code-button at the github-page of that repository. More information here

For more information about protocols used by git, read the page about git server protocols.

Mime
  • 1,142
  • 1
  • 9
  • 20
  • no still working with ssh url i run git push -u origin main and this is the result 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. – Ahlem Tbini Jun 03 '22 at 08:16
  • Have you added your public key to your github profile and are you using the right ssh key while pushing? https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent and https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account – Mime Jun 03 '22 at 08:23
2

So there's a few things going on here I think:

  1. The error from your first screen shot looks like it may be caused by having cloned the repository using the plain git:// protocol which doesn't do any type of authentication/authorization. Meaning you can git pull but you won't be able to git push.

  2. If you want to update your git config to automatically use https when pushing, you can add something like this to your gitconfig:

[url "https://github.com/"]
    pushInsteadOf = git://github.com/
  1. Alternatively if you want to use SSH instead of git:// or https:// protocol (and have your public key uploaded to your GH account) you can add
[url "git@github.com:"]
    pushInsteadOf = git://github.com/
    pushInsteadOf = https://github.com/

deric4
  • 1,095
  • 7
  • 11
  • 4
    GitHub have also dropped support for the `git://` protocol, so it's a good idea to stop using such URLs. – torek Jun 03 '22 at 11:25
2

I had this error while running git submodule update --init.

I fixed the problem by changing all my git:// submodules to https:// submodules in the .gitmodules file.

Then I ran

git submodule sync

After that my submodule update worked properly.

simlmx
  • 999
  • 12
  • 17
1

In my case I figured out my flutter project was trying to fetch a dependency from an URL on the pubspec.yaml with the following format: "git:github.com/repository"...To fix it I just had to change the "git" for "https".

Ramiro G.M.
  • 357
  • 4
  • 7