Lesstep
Azure DevOps Services and Server · REST API, Azure CLI and pipelines · Checked October 24, 2026

Azure DevOps: "TF401398: The pull request cannot be activated because the source and/or the target branch no longer exists, or the requested refs are not branches"

Azure DevOps answers TF401398 when it cannot take the source or the target of a new pull request as a branch on the server. The message covers two different mistakes and does not say which branch it means: a branch that is not there (never pushed, its push was refused, or it was deleted), and a name that is not a branch reference, such as develop where the REST API wants refs/heads/develop.

The whole answer

HTTP/1.1 400 Bad Request

{"$id":"1","innerException":null,"message":"TF401398: The pull request cannot be activated because the source and/or the target branch no longer exists, or the requested refs are not branches","typeName":"Microsoft.TeamFoundation.Git.Server.GitPullRequestCannotBeActivated, Microsoft.TeamFoundation.Git.Server","typeKey":"GitPullRequestCannotBeActivated",…}

Find out which branch

The causes public reports name

  1. The name is not in the refs/heads/ form. The REST API takes sourceRefName and targetRefName as full references, refs/heads/develop; a May 2024 report about Scala Steward sent the target as develop and got TF401398. The prefix twice fails the same way: a 2020 report about a pipeline task sent refs/heads/refs/heads/…, because the variable $(Build.SourceBranch) already holds refs/heads/…. A September 2024 Dependabot report had refs/heads/master end up inside a branch name.
  2. The source branch never reached the server. It was not pushed, or the push was refused, and the pull request then has no source. In two 2021 Dependabot reports, the build service identity that ran the pipeline lacked a permission; both found that the project had two build service identities, and one report names Contribute to pull requests. With the permission set on the right identity, the pull request was created. A refused push says why in its own output: see TF402455 for a protected branch.
  3. A branch with the name of the folder. Git cannot hold a branch dependabot and a branch dependabot/nuget/… at the same time, so the push of the second fails. A 2021 Dependabot report fixed TF401398 by deleting the branch named dependabot.
  4. The branch was deleted after it was checked, for example the target by someone else, or the source by the completion of an earlier pull request that deleted it.

What to do

  1. Look both names up as above.
  2. The source is missing: push it (git push -u origin <branch>) and read the push output; a refused push leaves no branch.
  3. The target is missing: choose a target that is listed under Repos → Branches. The repository's default branch is marked there.
  4. Both are listed: check how the names are sent. In a script or a REST call, send refs/heads/<name> exactly once.

Azure DevOps pull requests in IntelliJ IDEA and Rider

Azure DevOps Pull Requests, a plugin by Lesstep for JetBrains IDEs 2024.1 or later and Android Studio, reads the organization, project and repository from your git remote and lists the pull requests that wait for your review in an IDE tool window, on Azure DevOps Services and on Azure DevOps Server. Create Azure DevOps Pull Request first checks that the current branch is on the server, and opens the IDE's push dialog when it is not; the target is chosen from the branches the server has. From version 1.0.37, when Azure DevOps still answers TF401398, it looks both branches up and names the one that is missing. The review inbox is free; voting, commenting, completing and creating are Pro, with a 30-day trial.

Get it on JetBrains Marketplace

Azure DevOps is a trademark of Microsoft Corporation; IntelliJ IDEA and Rider are trademarks of JetBrains s.r.o. This page is not affiliated with or endorsed by Microsoft or JetBrains.

More: TF401179: an active pull request already exists · TF402455: pushes to this branch are not permitted · TF401175: no branch by that name · 日本語