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

Re: getting pull/push/fetch url

From
Eric Sunshine <sunshine@sunshineco.com>
Date
May 17, 2019, 08:09 UTC
Message-ID
<CAPig+cQ0MB4F++JDC-RO2SFA4Hv7DiEW4hNJGQs71Wi75pXuOg@mail.gmail.com>
In-Reply-To
<CAGqZTUvTg5S_-i9JjOwEG75CY+xFXJHAwTqh8uLG3SQTa3O0YA@mail.gmail.com>
On Fri, May 17, 2019 at 3:30 AM clime <clime7@gmail.com> wrote:
Show 15 quoted lines
> for my app, i need to be able get remote urls (fetch/pull/push) so
> that i can derive some information from those, e.g. pull url netloc
> from which i derive where other custom endpoints (binary file storage)
> related to the remote git repo is located. This is just one example. I
> am also using fetch url to store it into the composed package that i
> generate by the app.
>
> Now, the problem is that getting those urls (fetch/pull/push) doesn't
> seem to be an easy task. Currently i have the attached scripts to do
> that. But i noticed that older gits like 1.7 use origin as a fallback
> for pull url whereas the newer raise an error.
>
> My question is if there is a better way to determine the urls that
> would be backward compatible and easier than what i am doing right
> now.

Perhaps not a complete answer (and I'm sure people more familiar with the topic can provide better direction), but have you tried querying this information via higher-level commands rather than low-level git-config? For instance, to get the name of the remote for a branch:

    git branch --list --format='%(upstream:remotename)' $BRANCH
and, to get the fetch URL for a remote:
    git remote get-url $REMOTE
or the push URL:
    git remote get-url --push $REMOTE
Previous: climeNext: clime
Message 2 of 4 in “getting pull/push/fetch url”
  1. climeMay 17, 2019
  2. Eric SunshineMay 17, 2019
  3. climeMay 17, 2019
  4. climeMay 17, 2019

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.