{"record":{"id":"90639d2332bcb5ad","repo":"nikivdev/code","slug":"specify-branch-with-f-upstream-setup-branch-br","errorCode":null,"errorMessage":"Specify branch with: f upstream setup --branch <branch-name>","messagePattern":"Specify branch with: f upstream setup --branch <branch-name>","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/upstream.rs","lineNumber":199,"sourceCode":"\n    // Determine upstream branch (explicit > HEAD > main > master)\n    let upstream_branch = if let Some(branch) = upstream_branch {\n        branch.to_string()\n    } else if let Ok(head_ref) = git_capture(&[\"symbolic-ref\", \"refs/remotes/upstream/HEAD\"]) {\n        head_ref.trim().replace(\"refs/remotes/upstream/\", \"\")\n    } else if git_capture(&[\"rev-parse\", \"--verify\", \"refs/remotes/upstream/main\"]).is_ok() {\n        \"main\".to_string()\n    } else if git_capture(&[\"rev-parse\", \"--verify\", \"refs/remotes/upstream/master\"]).is_ok() {\n        \"master\".to_string()\n    } else {\n        // List available branches\n        let branches = git_capture(&[\"branch\", \"-r\", \"--list\", \"upstream/*\"])?;\n        println!(\"Cannot auto-detect upstream branch.\");\n        println!(\"Available upstream branches:\");\n        for line in branches.lines() {\n            println!(\"  {}\", line.trim());\n        }\n        bail!(\"Specify branch with: f upstream setup --branch <branch-name>\");\n    };\n\n    // Check if upstream branch exists on remote\n    let remote_ref = format!(\"refs/remotes/upstream/{}\", upstream_branch);\n    if git_capture(&[\"rev-parse\", \"--verify\", &remote_ref]).is_err() {\n        let branches = git_capture(&[\"branch\", \"-r\", \"--list\", \"upstream/*\"])?;\n        println!(\"Branch 'upstream/{}' not found.\", upstream_branch);\n        println!(\"Available upstream branches:\");\n        for line in branches.lines() {\n            println!(\"  {}\", line.trim());\n        }\n        bail!(\"Specify branch with: f upstream setup --branch <branch-name>\");\n    }\n\n    // Create or update local upstream branch\n    let local_upstream_exists =\n        git_capture(&[\"rev-parse\", \"--verify\", \"refs/heads/upstream\"]).is_ok();\n    let upstream_ref = format!(\"upstream/{}\", upstream_branch);","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/upstream.rs#L181-L217","documentation":"`setup_upstream_internal` (src/upstream.rs:~195) tries to auto-detect which branch of the `upstream` remote to track. When detection fails (branch argument not supplied and remote branches cannot be inferred), it prints the available `upstream/*` branches and bails, asking the user to name the branch explicitly.","triggerScenarios":"Calling `f upstream setup` without `--branch` while `git branch -r --list upstream/*` yields branches that can't be auto-selected (ambiguous, e.g. master + main + develop) or none resolvable.","commonSituations":"Upstream repo uses an unusual default branch name or has both `master` and `main`; user forgot `--branch` after adding the remote; upstream branches not yet fetched locally so the list is incomplete.","solutions":["Run the command from the printed list, e.g. `f upstream setup --branch main` (or master/develop).","Fetch first so remote branches are visible: `git fetch upstream`, then retry setup.","Confirm the upstream's default branch (`git remote show upstream` or the repo's GitHub page) and pass that name.","If tracking a specific feature line, pass its exact remote branch name with --branch."],"exampleFix":"// before (fails, ambiguous branches)\nf upstream setup\n// after\nf upstream setup --branch main","handlingStrategy":"validation","validationCode":"# detect and pass the upstream default branch explicitly\nBRANCH=\"$(git remote show upstream | awk '/HEAD branch/{print $NF}')\"\nf upstream setup --branch \"$BRANCH\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass --branch explicitly when upstream has master+main or nonstandard defaults.","Run `git fetch upstream` so remote branches are resolvable before setup.","Look up the upstream's default branch on the hosting site first.","Script the detection: `git remote show upstream | awk '/HEAD branch/{print $NF}'`."],"tags":["git","branch","upstream","configuration"],"backgroundTag":"git-branch-not-specified","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}