threads / bug / 63343

Potential bug in for-each-ref handling of fetch/push refspec

Subject: Potential bug in for-each-ref handling of fetch/push refspec

## tl;dr

One message between Apr 24, 2025 and Apr 24, 2025.

replies: 0people: 1as markdown or json

Sam Harwell· Apr 24, 2025, 20:57 UTC · lore

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)
I attempted to use fetch and push refspec to make an Azure DevOps repository (no forks) behave more like a GitHub contributor model (with forks). For example, the 'main' and 'rel/*' branches are considered upstream, and 'dev/user/branch' is the format used by each user for working branches. Here's an example configuration showing three remotes: 1) origin maps every local branch 'name' to remote branch 'dev/sharwell/name'; 2) devdiv does not rename branches but restricts the view to just main and rel/*; 3) partner maps local branch 'name' to 'dev/partner/name', representing the work done by username partner.
[remote "origin"]
	url = https://path/to/repo
	fetch = +refs/heads/dev/sharwell/*:refs/remotes/origin/*
	push = refs/heads/*:refs/heads/dev/sharwell/*
[remote "devdiv"]
	url = https://path/to/repo
	fetch = +refs/heads/main:refs/remotes/devdiv/main
	fetch = +refs/heads/rel/*:refs/remotes/devdiv/rel/*
[remote "partner"]
	url = https://path/to/repo
	fetch = +refs/heads/dev/partner/*:refs/remotes/partner/*
	push = refs/heads/*:refs/heads/dev/partner/*
What did you expect to happen? (Expected behavior)
I expected get-for-each-ref to consider refspecs for newly-created local branches than are not pushed. For example, consider the following command:
git for-each-ref --format="%(push:track,nobracket)::%(upstream:track,nobracket)::%(push)::%(upstream)::%(refname:short)" refs/heads/newLocalBranch
I expected this to print out:
::::::::newLocalBranch
What happened instead? (Actual behavior)
The command printed out:
gone::::refs/remotes/origin/newLocalBranch::::newLocalBranch
What's different between what you expected and what actually happened?

The command printed 'gone' instead of the empty string for '%(push:track,nobracket)'. The command printed 'refs/remotes/origin/newLocalBranch' instead of the empty string for '%(push)'.

Anything else you want to add:

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.49.0.windows.1
cpu: x86_64
built from commit: cca1f38702730b35f52c29efd62864b85e85ddcc
sizeof-long: 4
sizeof-size_t: 8
shell-path: D:/git-sdk-64-build-installers/usr/bin/sh
feature: fsmonitor--daemon
libcurl: 8.12.1
OpenSSL: OpenSSL 3.2.4 11 Feb 2025
zlib: 1.3.1
uname: Windows 10.0 26100 
compiler info: gnuc: 14.2
libc info: no libc information available
$SHELL (typically, interactive shell): <unset>
[Enabled Hooks]

← back to recent threads