{"record":{"id":"6bfca39576873d55","repo":"pcottle/learnGitBranching","slug":"git-error-exist","errorCode":null,"errorMessage":"git-error-exist","messagePattern":"git-error-exist","errorType":"exception","errorClass":"GitError","httpStatus":null,"severity":"error","filePath":"src/js/git/commands.js","lineNumber":27,"sourceCode":"var CommandResult = Errors.CommandResult;\n\nvar ORIGIN_PREFIX = 'o/';\n\nvar crappyUnescape = function(str) {\n  return str.replace(/&#x27;/g, \"'\").replace(/&#x2F;/g, \"/\");\n};\n\nfunction isColonRefspec(str) {\n  return str.indexOf(':') !== -1 && str.split(':').length === 2;\n}\n\nvar assertIsRef = function(engine, ref) {\n  engine.resolveID(ref); // will throw git error if can't resolve\n};\n\nvar assertRefNoModifiers = function(ref) {\n  if (/~|\\^/.test(ref)) {\n    throw new GitError({\n      msg: intl.str('git-error-exist', {ref: ref})\n    });\n  }\n}\n\nvar validateBranchName = function(engine, name) {\n  return engine.validateBranchName(name);\n};\n\nvar validateOriginBranchName = function(engine, name) {\n  return engine.origin.validateBranchName(name);\n};\n\nvar validateBranchNameIfNeeded = function(engine, name) {\n  if (engine.refs[name]) {\n    return name;\n  }\n  return validateBranchName(engine, name);","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/pcottle/learnGitBranching/blob/5b09d0ff9678cad164f5a7488a279a44f90d7256/src/js/git/commands.js#L9-L45","documentation":"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.","triggerScenarios":"Passing a modified ref like 'git branch main~2 foo' or any command config that calls assertRefNoModifiers with 'bug^' or 'v1~1'.","commonSituations":"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.","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"],"exampleFix":"// before\ngit branch main~2 mycopy\n// after\ngit branch mycopy main~2  // modified ref allowed as SOURCE, plain name as TARGET","handlingStrategy":"validation","validationCode":"if (/~|\\^/.test(ref)) { /* strip modifier or ask user for plain ref */ }","typeGuard":"function isPlainRef(ref) { return typeof ref === 'string' && !/[~^]/.test(ref); }","tryCatchPattern":null,"preventionTips":["Validate user-supplied ref names with a regex before passing to commands","Split rev expressions into base ref + modifier yourself and handle explicitly"],"tags":["git","refs","validation"],"backgroundTag":"invalid-ref-specifier","analyzedSha":"5b09d0ff9678cad164f5a7488a279a44f90d7256","analyzedAt":"2026-08-27T13:53:49.057Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}