{"record":{"id":"e7b7d69a6dbef01f","repo":"pcottle/learnGitBranching","slug":"you-cannot-delete-main-branch-on-remote","errorCode":null,"errorMessage":"You cannot delete main branch on remote!","messagePattern":"You cannot delete main branch on remote!","errorType":"validation","errorClass":"GitError","httpStatus":null,"severity":"error","filePath":"src/js/git/index.js","lineNumber":1270,"sourceCode":"\n  // HAX HAX update main and remote tracking for main\n  chain = chain.then(function() {\n    var localCommit = this.getCommitFromRef(sourceLocation);\n    this.setTargetLocation(this.resolveID(ORIGIN_PREFIX + options.destination), localCommit);\n    return this.animationFactory.playRefreshAnimation(this.gitVisuals);\n  }.bind(this));\n\n  if (!options.dontResolvePromise) {\n    this.animationQueue.thenFinish(chain);\n  }\n};\n\nGitEngine.prototype.pushDeleteRemoteBranch = function(\n  remoteBranch,\n  branchOnRemote\n) {\n  if (branchOnRemote.get('id') === 'main') {\n    throw new GitError({\n      msg: intl.todo('You cannot delete main branch on remote!')\n    });\n  }\n  // ok so this isn't too bad -- we basically just:\n  // 1) instruct the remote to delete the branch\n  // 2) kill off the remote branch locally\n  // 3) find any branches tracking this remote branch and set them to not track\n  var id = remoteBranch.get('id');\n  this.origin.deleteBranch(branchOnRemote);\n  this.deleteBranch(remoteBranch);\n  this.branchCollection.each(function(branch) {\n    if (branch.getRemoteTrackingBranchID() === id) {\n      branch.setRemoteTrackingBranchID(null);\n    }\n  }, this);\n\n  // animation needs to be triggered on origin directly\n  this.origin.pruneTree();","sourceCodeStart":1252,"sourceCodeEnd":1288,"githubUrl":"https://github.com/pcottle/learnGitBranching/blob/5b09d0ff9678cad164f5a7488a279a44f90d7256/src/js/git/index.js#L1252-L1288","documentation":"The remote's main branch is protected: pushDeleteRemoteBranch refuses to delete a remote ref whose id is 'main'. Real hosting services (GitHub, GitLab) similarly protect the default branch from deletion.","triggerScenarios":"Calling git push origin :main (or the push API with a delete intent) where branchOnRemote.get('id') === 'main'.","commonSituations":"Trying to clean up 'all' remote branches with a wildcard delete; level scripts iterating remote refs for deletion.","solutions":["Delete a non-default branch instead","If the remote truly must be reset, force-push main to an earlier commit rather than deleting it","Filter 'main' out of any branch-deletion loops"],"exampleFix":"// before\ngit push origin :main\n// after\ngit push origin :feature","handlingStrategy":"validation","validationCode":"if (branchOnRemote.get('id') === 'main') throw new Error('refusing to delete main');","typeGuard":"function isProtectedBranch(ref) { return ref.get('id') === 'main'; }","tryCatchPattern":null,"preventionTips":["Exclude the default branch from deletion loops","Use force-push to move main instead of deleting it"],"tags":["git","push","remote","protected-branch","delete"],"backgroundTag":"git-protected-branch-delete","analyzedSha":"5b09d0ff9678cad164f5a7488a279a44f90d7256","analyzedAt":"2026-08-27T13:53:49.057Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}