mislav/hub · error

could not determine project for head branch

Error message

could not determine project for head branch

What it means

pullRequest determines the head project (owner/repo) for the new pull request via localRepo.RemoteBranchAndProject. If the current branch has no resolvable remote project on the given host, the command cannot determine where the head branch lives and aborts with this error via utils.Check.

Source

Thrown at commands/pull_request.go:151

func pullRequest(cmd *Command, args *Args) {
	localRepo, err := github.LocalRepo()
	utils.Check(err)

	currentBranch, currentBranchErr := localRepo.CurrentBranch()

	baseProject, err := localRepo.MainProject()
	utils.Check(err)

	host, err := github.CurrentConfig().PromptForHost(baseProject.Host)
	if err != nil {
		utils.Check(github.FormatError("creating pull request", err))
	}
	client := github.NewClientWithHost(host)

	trackedBranch, headProject, _ := localRepo.RemoteBranchAndProject(host.User, false)
	if headProject == nil {
		utils.Check(fmt.Errorf("could not determine project for head branch"))
	}

	var (
		base, head string
	)

	if flagPullRequestBase := args.Flag.Value("--base"); flagPullRequestBase != "" {
		baseProject, base = parsePullRequestProject(baseProject, flagPullRequestBase)
	}

	if flagPullRequestHead := args.Flag.Value("--head"); flagPullRequestHead != "" {
		headProject, head = parsePullRequestProject(headProject, flagPullRequestHead)
	}

	baseRemote, _ := localRepo.RemoteForProject(baseProject)
	if base == "" && baseRemote != nil {
		base = localRepo.DefaultBranch(baseRemote).ShortName()
	}

View on GitHub (pinned to 5c547ed804)

Solutions

  1. Add a remote pointing at the GitHub repo: git remote add origin git@github.com:owner/repo.git
  2. Push the current branch: git push -u origin <branch>
  3. Ensure the remote URL matches the configured GitHub host (or pass --host / GITHUB_HOST appropriately)
  4. Specify the head explicitly with -h <owner>:<branch> if supported

Example fix

# before
$ git remote -v
(no output)
# after
$ git remote add origin git@github.com:me/myrepo.git
$ git push -u origin my-feature
$ hub pull-request
Defensive patterns

Strategy: validation

Validate before calling

git remote get-url origin >/dev/null 2>&1 || { echo "Add origin remote first"; exit 1; }
git ls-remote --heads origin $(git rev-parse --abbrev-ref HEAD) | grep -q . || { echo "Push branch first"; exit 1; }

Prevention

When it happens

Trigger: Creating a pull request when the current branch (or repo) has no remote pointing to the GitHub host, or the branch is not pushed and no project can be deduced for host.User.

Common situations: Fresh local repo without a GitHub remote; fork workflows where remote names differ (not origin); enterprise host mismatch where the remote URL doesn't match the configured host; branch never pushed.

Related errors


AI-assisted analysis of mislav/hub@5c547ed804 (2026-09-01). Data as JSON: /api/errors/783923c35a90e82e. Report an issue: GitHub.