# [BUG] git credential url field ordering/documentation issue

1 messages from 2025-08-11 to 2025-08-11. Participants: Muhammad Fahri Muharram.
Thread: https://gitlist.dev/t/63940

## Muhammad Fahri Muharram, 2025-08-11 11:19

Subject: [BUG] git credential url field ordering/documentation issue
Message-ID: <CACEVnOLzZkR_oELBFg2Wfu83cos8VRCNprx3Vad_wtDncFPQtw@mail.gmail.com>
URL: https://gitlist.dev/e/CACEVnOLzZkR_oELBFg2Wfu83cos8VRCNprx3Vad_wtDncFPQtw%40mail.gmail.com

```
In git credential source code, whenever an url field is encountered it
will call credential_from_url_1 which will then call credential_clear
on the credential struct.
https://github.com/git/git/blob/master/credential.c#L625

This means the credential struct is cleared whenever a url= line is
processed, but the documentation does not mention that the url field
must be placed before other fields to avoid wiping them.

This causes confusing behaviour:

$ printf "host=github.com\nusername=A\nprotocol=https" | git credential approve
$ printf "username=A\nurl=https://github.com" | git credential fill
Password for 'https://SeeStarz@github.com':
protocol=https
host=github.com
username=SeeStarz
password=
$ printf "url=https://github.com\nusername=A" | git credential fill
protocol=https
host=github.com
username=A
password=B

On the second command, due to username being wiped, git credential
fill defaults to using ~/.gitconfig which in my case uses the username
SeeStarz.
The expected behaviour is that both invocations of git credential fill
show username=A and password=B.
Please consider clarifying this behavior in the documentation or
adjusting the implementation to avoid this surprising side effect.

Thank you.

```
