pcottle/learnGitBranching · error · GitError
git-error-exist
Error message
git-error-exist
What it means
Thrown by assertRefNoModifiers when a ref argument contains ~ or ^ (commit-navigation modifiers). GitError signals the command was given something like main~2 where a plain ref is required; real git rejects ref-creation/modification with modified refs too.
Source
Thrown at src/js/git/commands.js:27
var CommandResult = Errors.CommandResult;
var ORIGIN_PREFIX = 'o/';
var crappyUnescape = function(str) {
return str.replace(/'/g, "'").replace(///g, "/");
};
function isColonRefspec(str) {
return str.indexOf(':') !== -1 && str.split(':').length === 2;
}
var assertIsRef = function(engine, ref) {
engine.resolveID(ref); // will throw git error if can't resolve
};
var assertRefNoModifiers = function(ref) {
if (/~|\^/.test(ref)) {
throw new GitError({
msg: intl.str('git-error-exist', {ref: ref})
});
}
}
var validateBranchName = function(engine, name) {
return engine.validateBranchName(name);
};
var validateOriginBranchName = function(engine, name) {
return engine.origin.validateBranchName(name);
};
var validateBranchNameIfNeeded = function(engine, name) {
if (engine.refs[name]) {
return name;
}
return validateBranchName(engine, name);View on GitHub (pinned to 5b09d0ff96)
Solutions
- Use a plain branch/tag name without ~ or ^
- Create a branch at that commit first, then operate on the branch
- If you want to detach/inspect, use a command that accepts revs (e.g. checkout) instead
Example fix
// before git branch main~2 mycopy // after git branch mycopy main~2 // modified ref allowed as SOURCE, plain name as TARGET
Defensive patterns
Strategy: validation
Validate before calling
if (/~|\^/.test(ref)) { /* strip modifier or ask user for plain ref */ } Type guard
function isPlainRef(ref) { return typeof ref === 'string' && !/[~^]/.test(ref); } Prevention
- Validate user-supplied ref names with a regex before passing to commands
- Split rev expressions into base ref + modifier yourself and handle explicitly
When it happens
Trigger: Passing a modified ref like 'git branch main~2 foo' or any command config that calls assertRefNoModifiers with 'bug^' or 'v1~1'.
Common situations: Copy-pasting a SHA/rev expression from git log output; scripts that append ~1 to user-supplied branch names; muscle memory from git checkout main~2.
Related errors
- ' + ref + ' is not a branch
- cannot fetch to ' + ref + ' when checked out on ' + ref
- ' + ref + ' is not a remote branch
- ' + generalArgs[0] + ' is not a remote in your repository! t
- ' + branchName + ' is not a branch!
AI-assisted analysis of pcottle/learnGitBranching@5b09d0ff96 (2026-08-27).
Data as JSON: /api/errors/6bfca39576873d55.
Report an issue: GitHub.