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

Cannot override `remote.origin.url` with `-c` option

From
MGMathew George <mathewegeorge@gmail.com>
Date
Jun 9, 2024, 06:51 UTC
Message-ID
<83D801A8-3878-43C1-B7A7-78B3B7315FD8@gmail.com>
> 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)

``` # Create a test repo to pull into git init test cd $_ git remote add origin wrong-url # Create a test repo to pull from git init ../test2 cd $_ touch a git add . git commit -m 'commit to pull' # Attempt to pull, setting remote.origin.url # The following git commands will fail: cd ../test git -c remote.origin.url=../test2 pull git -c remote.origin.url=../test2 fetch # However, this succeeds: git pull ../test2 ```

> What did you expect to happen? (Expected behavior)

The '-c' option should allow me to override the remote URL, which, as a result of running `git remote add`, is configured as follows in test/.git/config:

```
[remote "origin"]
	url = wrong-url
```
From git(1): 
```
-c <name>=<value>
    Pass a configuration parameter to the command. The
    value given will override values from configuration
    files.
```
> What happened instead? (Actual behavior)

The following errors are produced for both 'fetch' and 'pull' operations:

``` fatal: 'wrong-url' does not appear to be a git repository fatal: Could not read from remote repository.

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

Regardless of the -c option, the commands above use the url 'wrong-url' from .git/config.

> What's different between what you expected and what actually
> happened?
The -c option is not respected.
> Anything else you want to add:

It may be that this is not supported, but if that's the case, I missed any documentation saying so.

> Please review the rest of the bug report below.
> You can delete any lines you don't wish to share.

[System Info] git version: git version 2.45.2 cpu: x86_64 no commit associated with this build sizeof-long: 8 sizeof-size_t: 8 shell-path: /usr/bin/sh compiler info: clang: 17.0.2 (https://android.googlesource.com/toolchain/llvm-project d9f89f4d16663d5012e5c09495f3b30ece3d2362) libc info: no libc information available $SHELL (typically, interactive shell): /usr/bin/bash

[Enabled Hooks] not run from a git repository - no hooks to show

Next: Jeff King
Message 1 of 29 in “Cannot override `remote.origin.url` with `-c` option”
  1. Mathew GeorgeJun 9, 2024
  2. Jeff KingJun 11, 2024
  3. Junio C HamanoJun 11, 2024
  4. Jeff KingJun 13, 2024
  5. 0/11 allow overriding remote.*.urlJeff King, Jun 14, 2024
  6. 01/11 archive: fix check for missing urlJeff King, Jun 14, 2024
  7. 02/11 remote: refactor alias_url() memory ownershipJeff King, Jun 14, 2024
  8. Junio C HamanoJun 14, 2024
  9. 03/11 remote: transfer ownership of memory in add_url(), etcJeff King, Jun 14, 2024
  10. Junio C HamanoJun 14, 2024
  11. Jeff KingJun 16, 2024
  12. Junio C HamanoJun 17, 2024
  13. Elijah NewrenJun 25, 2024
  14. 04/11 remote: use strvecs to store remote url/pushurlJeff King, Jun 14, 2024
  15. Elijah NewrenJun 25, 2024
  16. 05/11 remote: simplify url/pushurl selectionJeff King, Jun 14, 2024
  17. Elijah NewrenJun 25, 2024
  18. 06/11 config: document remote.*.url/pushurl interactionJeff King, Jun 14, 2024
  19. Elijah NewrenJun 25, 2024
  20. 07/11 remote: allow resetting url listJeff King, Jun 14, 2024
  21. Elijah NewrenJun 25, 2024
  22. 08/11 t5801: make remote-testgit GIT_DIR setup more robustJeff King, Jun 14, 2024
  23. Elijah NewrenJun 25, 2024
  24. 09/11 t5801: test remote.*.vcs configJeff King, Jun 14, 2024
  25. 10/11 remote: always require at least one url in a remoteJeff King, Jun 14, 2024
  26. 11/11 remote: drop checks for zero-url caseJeff King, Jun 14, 2024
  27. Elijah NewrenJun 25, 2024
  28. Elijah NewrenJun 25, 2024
  29. Jeff KingJun 26, 2024

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.