pcottle/learnGitBranching · error · GitError
git-error-exist
Error message
git-error-exist
What it means
The ref string completely fails to match the ID-plus-optional-relative-suffix grammar ^([a-zA-Z0-9]+)(([~^]\d*)*)$. This is not a partial match failure — the whole token is malformed (illegal characters, leading ~, empty name, etc.), so resolution cannot even begin.
Source
Thrown at src/js/git/index.js:1813
if (this.refs[ref]) {
return this.refs[ref];
}
// Commit hashes like C4 are case insensitive
if (ref.match(/^c\d+'*/) && this.refs[ref.toUpperCase()]) {
return this.refs[ref.toUpperCase()];
}
// Attempt to split ref string into a reference and a string of ~ and ^ modifiers.
var startRef = null;
var relative = null;
var regex = /^([a-zA-Z0-9]+)(([~\^]\d*)*)$/;
var matches = regex.exec(ref);
if (matches) {
startRef = matches[1];
relative = matches[2];
} else {
throw new GitError({
msg: intl.str('git-error-exist', {ref: ref})
});
}
if (!this.refs[startRef]) {
throw new GitError({
msg: intl.str('git-error-exist', {ref: ref})
});
}
var commit = this.getCommitFromRef(startRef);
if (relative) {
commit = this.resolveRelativeRef( commit, relative );
}
return commit;
};
View on GitHub (pinned to 5b09d0ff96)
Solutions
- Use only alphanumeric ref names in this engine (branches like main, side, not my-branch)
- Fix the suffix so it is a valid ~N/^N chain attached to a name
- Validate the ref against the regex before calling
Example fix
// before
this.resolveID('o/main^');
// after
this.resolveID('o/main'); Defensive patterns
Strategy: type-guard
Validate before calling
var RX = /^([a-zA-Z0-9]+)(([~^]\d*)*)$/;
if (!RX.test(ref)) throw new Error('malformed ref'); Type guard
function isValidRefToken(ref) { return /^([a-zA-Z0-9]+)(([~^]\d*)*)$/.test(ref); } Prevention
- Restrict branch names to alphanumerics in this engine
- Sanitize programmatically built ref strings
When it happens
Trigger: Passing a ref containing characters outside [a-zA-Z0-9] or a malformed suffix, e.g. 'main-', '~2', 'o/main^', or an empty/whitespace string, to the ref resolver.
Common situations: Typos in commands; shell expansion inserting stray characters; programmatically constructed ref names with slashes/dashes that the engine's grammar rejects.
Related errors
- git-error-relative-ref
- git-error-exist
- cannot fetch to ' + ref + ' when checked out on ' + ref
- ' + ref + ' is not a branch
- ' + ref + ' is not a remote branch
AI-assisted analysis of pcottle/learnGitBranching@5b09d0ff96 (2026-08-27).
Data as JSON: /api/errors/556d67c1a6a88112.
Report an issue: GitHub.