git push to gerrit server doesn't work when setting git remote set-url --push, but works if I type in the URL manually

StackOverflow https://stackoverflow.com//questions/22003362

  •  20-12-2019
  •  | 
  •  

Question

I am having trouble pushing my code from git to gerrit. First I checked out the code like so:

git clone ssh://user@location.com:22/path/to/code

Then I tried setting up a push url like so:

git remote set-url --push origin "someotherlocation.com:/path/to/code HEAD:refs/for/master"

When I do git push it returns this error:

fatal: '/path/to/code HEAD:refs/for/master': not a Gerrit project
fatal: Could not read from remote repository.

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

However, if I just type in

git push someotherlocation.com:/path/to/code HEAD:refs/for/master

it gets pushed to the gerrit server. Why is this, and what am I doing wrong? Thanks!

Was it helpful?

Solution

Your git remote command sets the push URL to, literally, someotherlocation.com:/path/to/code HEAD:refs/for/master. A push URL is expected to be just the URL. The push refspec (HEAD:refs/for/master) is not part of the URL. If the goal is to avoid having to type the refspec every time I suggest you look into setting up a Git alias or investigate the remote.<name>.push option for .gitconfig (see git-config(1)).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top