Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git push with ssh remote fails unless verbose

Tags:

git

ssh

I have a git (version 2.1.2) repository with an ssh remote:

$ git remote -v
origin  ssh://[email protected]:/home/dettorer/my_project (fetch)
origin  ssh://[email protected]:/home/dettorer/my_project (push)

Which fails to push:

$ git push
Bad port ''
fatal: Could not read from remote repository.

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

Unless… I use the --verbose switch:

$ git push --verbose
Pushing to ssh://[email protected]:/home/dettorer/my_project
Enter passphrase for key '/home/dettorer/.ssh/id_rsa': 
Counting objects: 7, done.
...
To ssh://[email protected]:/home/dettorer/my_project
   e633fe9..5d2e9de  master -> master
updating local tracking ref 'refs/remotes/origin/master'

I augmented the ssh log level as hinted in that answer, but the output for git push (without --verbose) was the exact same.

Where could it come from?

As nwinkler suggested, here is the output of the two commands with GIT_TRACE=2:

$ GIT_TRACE=2 git push
13:42:33.002392 git.c:349               trace: built-in: git 'push'
13:42:33.033594 run-command.c:341       trace: run_command: 'ssh' '-p' '' '[email protected]' 'git-receive-pack '\''/home/dettorer/my_project'\'''
Bad port ''
fatal: Could not read from remote repository.

Please make sure you have the correct access rights

$ GIT_TRACE=2 git push -v
13:42:39.929236 git.c:349               trace: built-in: git 'push' '-v'
Pushing to ssh://[email protected]:/home/dettorer/my_project
13:42:39.944837 run-command.c:341       trace: run_command: 'ssh' '[email protected]' 'git-receive-pack '\''/home/dettorer/my_project'\'''
Enter passphrase for key '/home/dettorer/.ssh/id_rsa':

So unless I use --verbose, there indeed is an extra '-p' option with an empty argument.

EDIT: this is getting more obscure:

$ git push origin
Bad port ''
fatal: Could not read from remote repository.

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

$ git remote add test test
$ git push origin
Enter passphrase for key '/home/dettorer/.ssh/id_rsa': 

$ git remote remove test
$ git push origin
Bad port ''
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
like image 869
Dettorer Avatar asked Dec 11 '14 12:12

Dettorer


People also ask

What is git remote verbose?

Invoking git remote with the -v option will print the list of bookmarked repository names and additionally, the corresponding repository URL. The -v option stands for "verbose". Below is example output of verbose git remote output. git remote -v origin git@bitbucket.

Why is my git push failing?

This error mainly occurs when you attempt to push your local changes to GitHub while the local repository (repo) has not yet been updated with any changes made in the remote repo. So Git is trying to tell you to update the local repo with the current changes in the remote before pushing your own changes.

How do I fix failed to push some refs to git errors?

To fix this issue, run git pull on your local repository. This should allow you to push to origin again.


2 Answers

OK, after seeing your comments, I'm pretty sure I know what's wrong.

Can you try to change your remote URL to this:

ssh://[email protected]/home/dettorer/my_project

You've got an extra colon there, which seems to be causing the issue of the additional port. I don't know why running it with -v fixes the problem.

The git help shows that the following is the supported format for the ssh protocol:

ssh://[user@]host.xz[:port]/path/to/repo.git/

As you can see, the colon is only required if you need to set a port. Leave it off if you want to use the standard port.

like image 158
nwinkler Avatar answered Oct 18 '22 18:10

nwinkler


Note: with Git 2.3.7 (released yesterday, April, 27 2015), this error "Bad port ''" is no more.

See commit ad34ad6, from commit 6b6c5f7 (by Torsten Bögershausen tboegi)

connect.c: ignore extra colon after hostname

Ignore an extra ':' at the end of the hostname in URL's like "ssh://example.com:/path/to/repo"

The colon is meant to separate a port number from the hostname.
If the port is empty, the colon should be ignored, see RFC 3986.

It had been working for URLs with ssh:// scheme, but was unintentionally broken in 86ceb3, "allow ssh://user@[2001:db8::1]/repo.git" (Git 2.3.4).

like image 37
VonC Avatar answered Oct 18 '22 17:10

VonC