pcottle/learnGitBranching · error · GitError
git-result-nothing
Error message
git-result-nothing
What it means
`git checkout -` moves HEAD back to where it was before the last move. This error is thrown when there is no previous position recorded (HEAD.lastLastTarget is unset), so there is nothing to go 'back' to.
Source
Thrown at src/js/git/commands.js:906
var args = null;
if (commandOptions['-b']) {
// the user is really trying to just make a
// branch and then switch to it. so first:
args = commandOptions['-b'].concat(generalArgs);
command.twoArgsImpliedHead(args, '-b');
var validId = engine.validateBranchName(args[0]);
engine.branch(validId, args[1]);
engine.checkout(validId);
return;
}
if (commandOptions['-']) {
// get the heads last location
var lastPlace = engine.HEAD.get('lastLastTarget');
if (!lastPlace) {
throw new GitError({
msg: intl.str('git-result-nothing')
});
}
engine.HEAD.set('target', lastPlace);
return;
}
if (commandOptions['-B']) {
args = commandOptions['-B'].concat(generalArgs);
command.twoArgsImpliedHead(args, '-B');
engine.forceBranch(args[0], args[1]);
engine.checkout(args[0]);
return;
}
command.validateArgBounds(generalArgs, 1, 1);
View on GitHub (pinned to 5b09d0ff96)
Solutions
- Use an explicit ref: `git checkout main` or `git checkout <branch>`
- Perform at least one checkout/switch before using `-`
- Use `git switch -` only after a prior switch has been recorded
Example fix
// before git checkout - // after git checkout main
Defensive patterns
Strategy: validation
Validate before calling
if (engine.HEAD.get('lastLastTarget')) { engine.checkout('-'); } else { engine.checkout('main'); } Prevention
- Perform one explicit checkout before using `checkout -`
- Treat `-` as history nav, not a default target
- Script explicit refs instead of `-` in tests
When it happens
Trigger: Running `git checkout -` as the first HEAD-moving command (no prior checkout/switch in the session), or after history of the previous target was cleared.
Common situations: User dashes off `checkout -` immediately after starting a level or after `git reset` scenarios that never set a prior target.
Related errors
- git-error-options
- git-error-remote-branch
- git-error-exist
- cannot fetch to ' + ref + ' when checked out on ' + ref
- ' + ref + ' is not a branch
AI-assisted analysis of pcottle/learnGitBranching@5b09d0ff96 (2026-08-27).
Data as JSON: /api/errors/24cf046012310216.
Report an issue: GitHub.