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

  1. Use a plain branch/tag name without ~ or ^
  2. Create a branch at that commit first, then operate on the branch
  3. 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

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


AI-assisted analysis of pcottle/learnGitBranching@5b09d0ff96 (2026-08-27). Data as JSON: /api/errors/6bfca39576873d55. Report an issue: GitHub.