{"record":{"id":"36dba62dba869f95","repo":"nikivdev/code","slug":"git-push-failed","errorCode":null,"errorMessage":"git push failed","messagePattern":"git push failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/publish.rs","lineNumber":994,"sourceCode":"    let branch = Command::new(\"git\")\n        .args([\"rev-parse\", \"--abbrev-ref\", \"HEAD\"])\n        .output()\n        .context(\"failed to get current branch\")?;\n\n    let branch = String::from_utf8_lossy(&branch.stdout).trim().to_string();\n    let branch = if branch.is_empty() || branch == \"HEAD\" {\n        \"main\".to_string()\n    } else {\n        branch\n    };\n\n    let status = Command::new(\"git\")\n        .args([\"push\", \"-u\", \"origin\", &branch])\n        .status()\n        .context(\"failed to push to origin\")?;\n\n    if !status.success() {\n        bail!(\"git push failed\");\n    }\n\n    Ok(())\n}\n","sourceCodeStart":976,"sourceCodeEnd":999,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/publish.rs#L976-L999","documentation":"push_to_origin runs `git push -u origin <branch>` and, if the push exits non-zero, bails with 'git push failed'. This is the final step of GitHub publishing; the real cause (rejected non-fast-forward, auth failure, missing remote, protected branch) is printed by git on stderr just before this message.","triggerScenarios":"`git push -u origin <branch>` exits non-zero: remote contains work you don't have (non-fast-forward), SSH key/credential not authorized for the repo, remote 'origin' missing or wrong URL, branch name rejected by push rules.","commonSituations":"First push of an SSH-key-less machine to a new repo created via gh; pushing over https without a credential helper; repo URL pointing at a repo the user can't write to; simultaneous divergent pushes from another machine.","solutions":["Read git's stderr above the error: 'rejected' → `git pull --rebase` then retry; 'Permission denied (publickey)' → set up SSH keys or gh credential helper","Run `git remote -v` and confirm origin points at the correct repo you can push to","Test auth: `ssh -T git@github.com` or `gh auth status`","If you intend to overwrite, use `git push --force` deliberately (never as a default)"],"exampleFix":"// before: rejected non-fast-forward\ngit push -u origin main  ->  git push failed\n// after\ngit pull --rebase origin main\ngit push -u origin main","handlingStrategy":"retry","validationCode":"let out = std::process::Command::new(\"git\").args([\"remote\",\"get-url\",\"origin\"]).output()?;\nif !out.status.success() {\n    eprintln!(\"origin remote missing; add it before pushing\");\n    std::process::exit(1);\n}\n// auth probe\nlet t = std::process::Command::new(\"ssh\").args([\"-T\",\"git@github.com\"]).output();","typeGuard":null,"tryCatchPattern":"if let Err(e) = publish(opts) {\n    if e.to_string() == \"git push failed\" {\n        eprintln!(\"push rejected — inspect git stderr: rebase if non-fast-forward, fix SSH/credentials if auth failed\");\n    } else { return Err(e); }\n}","preventionTips":["Set up SSH keys or `gh auth setup-git` before first publish","Pull --rebase before pushing when working across machines","Verify origin URL points at a repo you can write to"],"tags":["git","push","network","authentication"],"backgroundTag":"git-push-rejected","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}