Feature request: git status --branch-only
- From
Ondra Medek <xmedeko@gmail.com>
- Date
- Nov 14, 2023, 10:16 UTC
- Message-ID
- <CAJsoDaFX7YdncsTy7UsjxaM1GCKs36-H5RhJ6kzgBUFBJyoGZQ@mail.gmail.com>
Hello, I am working on a tol which should fetch changes from a remote repository on a user click. I want to limit fetch on the current remote tracking branch (something like "origin/master"), but surprisingly, it's hard to get it for all corner cases like a fresh clone of an empty repository or detached head, etc. E.g see this SO thread https://stackoverflow.com/questions/171550/find-out-which-remote-branch-a-local-branch-is-tracking/52896538
The most reliable way for me is to call
git status -b --no-ahead-behind --porcelain=v2
and parse the "# branch.upstream" line output. However, it is a bit slow on large repos and yields unused output for me. So, I propose a new switch "git status --branch-only" which would output branch status only.
Note: workaround is to specify some non-existing directory, like
git status -b --no-ahead-behind --porcelain=v2 .this-dir-does-not-exists
Thanks Ondra Medek