Cannot override `remote.origin.url` with `-c` option
- From
- Mathew 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