How to clone without using username with gerrit?

1,297 views
Skip to first unread message

RAMANA REDDY

unread,
May 22, 2019, 8:13:34 AM5/22/19
to Repo and Gerrit Discussion
Hello people,

    When I clone a repo with username, it works fine

                  git clone ssh://username@gerrithost.net:29418/MyRepo

    I would like to do it without using username in the above command as in:

                  git clone ssh://gerrithost.net:29418/MyRepo

    This works in some of the laptops, but not in every laptop. What is the setting I need to do for the same to make it work on other laptops?

    I tried adding a global config with username and email (.gitconfig). This doesn't work.

    Any ideas

Sven Selberg

unread,
May 22, 2019, 8:33:40 AM5/22/19
to Repo and Gerrit Discussion
IIRC ssh picks up the current user name so it might be that you have different users on different laptops.
Solution: Use a user with the correct name

Since you aren't specifying how it fails it might also be that for some machines you have the correct username but the ssh-keys for this user is not added to Gerrit.
Solution: Add key to Gerrit


If you want to configure it you should do that in "~/.ssh/config" something like:
------------------------------------
    User username
------------------------------------

You could elaborate on this to create a gerrit short-cut if you'd like
------------------------------------
Host gerrit
    Hostname gerrithost.net
    User username
    Port 29418
------------------------------------

And clone with:

$ git clone ssh://gerrit/MyRepo

The downside of the ssh-config approaches is that remote git operations for origin can start failing in your local git if you change ~/.ssh/config which can be confusing.

BR
Sven

Gert van Dijk

unread,
May 22, 2019, 8:35:53 AM5/22/19
to RAMANA REDDY, Repo and Gerrit Discussion
It really depends on the platform that you're using. I'm going to assume Linux here with OpenSSH client being used by git helpers. Moreover, this is not specific to Gerrit, but is a plain git client configuration.

What I personally like to do is creating an OpenSSH client configuration (e.g. in ~/.ssh/config or globally in /etc/ssh/ssh_config) in which I specify the servers I connect to frequently. Example:

Host mygerrit1
  Hostname gerrit.corp.mycompany.tld
  # custom username for this Gerrit host
  Username gert.vandijk
  Port 29418

Host mygerrit2
  Hostname review.mydomain.tld
  # Custom SSH port for this one
  Port 12345

# Default for all hosts:
Host *
  User gertvdijk

After which 'mygerrit1' and 'mygerrit2' have become shortcuts available in all applications using OpenSSH client libraries, including git on Linux, e.g.:

$ git clone ssh://mygerrit2/MyRepo

Also when working with SSH commands to Gerrit, such as query:

$ ssh mygerrit2 gerrit version

I personally really like the OpenSSH client configuration approach, because I use plain SSH a lot too and like to have convenient shortcuts without having to specify all options on the command line every time.

HTH

David Pursehouse

unread,
May 22, 2019, 8:47:48 AM5/22/19
to RAMANA REDDY, Repo and Gerrit Discussion
On Wed, May 22, 2019 at 9:13 PM RAMANA REDDY <ramanar...@gmail.com> wrote:
Hello people,

    When I clone a repo with username, it works fine

                  git clone ssh://username@gerrithost.net:29418/MyRepo

    I would like to do it without using username in the above command as in:

                  git clone ssh://gerrithost.net:29418/MyRepo

    This works in some of the laptops, but not in every laptop. What is the setting I need to do for the same to make it work on other laptops?

Do you have any insteadOf setting configured in the .gitconfig on the machine(s) where it works?
 

    I tried adding a global config with username and email (.gitconfig). This doesn't work.

    Any ideas

--
--
To unsubscribe, email repo-discuss...@googlegroups.com
More info at http://groups.google.com/group/repo-discuss?hl=en

---
You received this message because you are subscribed to the Google Groups "Repo and Gerrit Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to repo-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/repo-discuss/39bed45a-ca8a-425f-b52b-e472f76962bc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Gert van Dijk

unread,
May 22, 2019, 9:02:31 AM5/22/19
to Repo and Gerrit Discussion
On Wed, May 22, 2019 at 2:47 PM David Pursehouse <david.pu...@gmail.com> wrote:
On Wed, May 22, 2019 at 9:13 PM RAMANA REDDY <ramanar...@gmail.com> wrote:
Hello people,

    When I clone a repo with username, it works fine

                  git clone ssh://username@gerrithost.net:29418/MyRepo

    I would like to do it without using username in the above command as in:

                  git clone ssh://gerrithost.net:29418/MyRepo

    This works in some of the laptops, but not in every laptop. What is the setting I need to do for the same to make it work on other laptops?

Do you have any insteadOf setting configured in the .gitconfig on the machine(s) where it works?

Just to elaborate on this a bit more, git-level config with insteadOf is another idea to this, yeah. E.g.:

[url "ssh://myuse...@gerrit.mydomain.tld:29418/"]
    insteadOf = ssh://gerrit1/


after which

$ git clone ssh://gerrit1/MyProject

should work.

This can be placed in git-config files at any level, so even possible to set this machine-wide, user-wide, or project-specific.

(You could even change protocol with this, and it could be quite confusing when trying to debug connection errors, I can tell you that.)

HTH

Andrew Grimberg

unread,
May 22, 2019, 9:13:10 AM5/22/19
to Gert van Dijk, RAMANA REDDY, Repo and Gerrit Discussion
On 5/22/19 5:35 AM, Gert van Dijk wrote:
> On Wed, May 22, 2019 at 2:13 PM RAMANA REDDY <ramanar...@gmail.com
> <mailto:ramanar...@gmail.com>> wrote:
>
>     When I clone a repo with username, it works fine
>
>                   git clone
> ssh://*username*@gerrithost.net:29418/MyRepo
> <http://gerrithost.net:29418/MyRepo>
>
>     I would like to do it without using username in the above
> command as in:
>
>                   git clone ssh://gerrithost.net:29418/MyRepo
> <http://gerrithost.net:29418/MyRepo>
>
>     This works in some of the laptops, but not in every laptop. What
> is the setting I need to do for the same to make it work on other
> laptops?
>
>     I tried adding a global config with username and email
> (.gitconfig). This doesn't work.
>
>
> It really depends on the platform that you're using. I'm going to assume
> Linux here with OpenSSH client being used by git helpers. /Moreover,
> this is not specific to Gerrit, but is a plain git client configuration./
>
> What I personally like to do is creating an OpenSSH client configuration
> (e.g. in ~/.ssh/config or globally in /etc/ssh/ssh_config) in which I
> specify the servers I connect to frequently. Example:
>
> Host mygerrit1
>   Hostname gerrit.corp.mycompany.tld
>   # custom username for this Gerrit host
>   Username gert.vandijk
>   Port 29418
>
> Host mygerrit2
>   Hostname review.mydomain.tld
>   # Custom SSH port for this one
>   Port 12345
>
> # Default for all hosts:
> Host *
>   User gertvdijk

I do something similar but instead of making shortcuts, I do the following:

--[cut]--
# Standard LF hosted gerrit systems
Host gerrit.*.* gerrit-new.*.*
Port 29418
User agrimberg
--[/cut]--

This does mean that I have to fully specify a particular hostname in my
cloning or ssh API operations, but it means I don't have to go and add a
section for any gerrit system unless they aren't named in a standard
fashion.

For a gerrit that follows the same host syntax that have a different
port or username, I can add specific overrides before the more generic
one in the file.

> After which 'mygerrit1' and 'mygerrit2' have become shortcuts available
> in all applications using OpenSSH client libraries, including git on
> Linux, e.g.:
>
> $ git clone ssh://mygerrit2/MyRepo
>
> Also when working with SSH commands to Gerrit, such as query:
>
> $ ssh mygerrit2 gerrit version
>
> I personally really like the OpenSSH client configuration approach,
> because I use plain SSH a lot too and like to have convenient shortcuts
> without having to specify all options on the command line every time.
>
> HTH
>
> --
> --
> To unsubscribe, email repo-discuss...@googlegroups.com
> More info at http://groups.google.com/group/repo-discuss?hl=en
>
> ---
> You received this message because you are subscribed to the Google
> Groups "Repo and Gerrit Discussion" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to repo-discuss...@googlegroups.com
> <mailto:repo-discuss...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/repo-discuss/CAFT%2BaqLGv1mkekZ%3D0zitLG_MkNT6ezXVJjJ9YO9rcZxNVSH87A%40mail.gmail.com
> <https://groups.google.com/d/msgid/repo-discuss/CAFT%2BaqLGv1mkekZ%3D0zitLG_MkNT6ezXVJjJ9YO9rcZxNVSH87A%40mail.gmail.com?utm_medium=email&utm_source=footer>.
signature.asc

RAMANA REDDY

unread,
May 22, 2019, 9:24:28 AM5/22/19
to Andrew Grimberg, Gert van Dijk, Repo and Gerrit Discussion
Thank you very much. So this has nothing to do with Gerrit, rather it is a configuration thing with ssh

The reason it worked on other laptops is that the username of laptop and Gerrit username are same!!

Thank you very much for your help!!!

I made it work by updating the ~/.ssh/config file

Reply all
Reply to author
Forward
0 new messages