git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Git bug report git remote get-url

From
Taylor Blau <me@ttaylorr.com>
Date
Jan 6, 2022, 00:22 UTC
Message-ID
<YdY2P+xX/a6aHB2b@nand.local>
In-Reply-To
<00FDB880-5FF6-4C67-9144-5599B2872830@interpublic.com>
On Wed, Jan 05, 2022 at 05:22:06PM +0000, Nanekrangsan, Sucheela (NYC-GIS) wrote:
Show 5 quoted lines
> Thank you for filling out a Git bug report!
> Please answer the following questions to help us understand your issue.
>
> What did you do before the bug happened? (Steps to reproduce your issue)
> 1. I put [remote] entries in /etc/gitconfig
This is almost certainly the culprit.

`git remote get-url` doesn't output anything (except the error message included in your report) when `remote->configured_in_repo` is zero. Indeed, looking at remote.c:handle_config() where we actually add a new remote:

    remote = make_remote(remote_state, name, namelen);
    remote->origin = REMOTE_CONFIG;
    if (current_config_scope() == CONFIG_SCOPE_LOCAL ||
        current_config_scope() == CONFIG_SCOPE_WORKTREE)
            remote->configured_in_repo = 1;

we only set configured_in_repo when we're looking at local or worktree configuration. Since $(prefix)/etc/gitconfig isn't either of those, we'll avoid setting configured_in_repo, hence we'll end up inside of this if-statement in builtin/remote.c:get_url():

    remote = remote_get(remotename);
    if (!remote_is_configured(remote, 1)) {
            error(_("No such remote '%s'"), remotename);
            exit(2);
    }
...producing the error message in your report.
> 4. After `git remote add xxx`, I can get the URL from `git remote get-url`.

This makes sense, since `git remote add` will configure the remote `xxx` in your repository-local configuration, not the system-wide one.

Thanks, Taylor

Previous: Nanekrangsan, Sucheela (NYC-GIS)
Message 2 of 2 in “Git bug report git remote get-url”
  1. Nanekrangsan, Sucheela (NYC-GIS)Jan 5, 2022
  2. Taylor BlauJan 6, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.