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",…}
- Public reports from 2018 to October 2026 quote it from the REST API, pipeline tasks that create pull requests, Dependabot and Renovate on Azure DevOps, and coding agents that open pull requests.
- "Source and/or target": the server does not say which one. A September 2026 report about such an agent notes exactly that, and that its code treats every TF401398 as a missing target only because it pushed the source just before.
Find out which branch
- With git:
git ls-remote --heads origin <source> <target>prints the ones the server has. A name that prints nothing is the one. - With the REST API:
GET …/_apis/git/repositories/<repository>/refs?filter=heads/<branch>. The filter matches the start of the name, soheads/mainalso listsmain-old: look forrefs/heads/<branch>exactly invalue. - In the web: Repos → Branches, and search for both names.
The causes public reports name
- The name is not in the
refs/heads/form. The REST API takessourceRefNameandtargetRefNameas full references,refs/heads/develop; a May 2024 report about Scala Steward sent the target asdevelopand got TF401398. The prefix twice fails the same way: a 2020 report about a pipeline task sentrefs/heads/refs/heads/…, because the variable$(Build.SourceBranch)already holdsrefs/heads/…. A September 2024 Dependabot report hadrefs/heads/masterend up inside a branch name. - 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.
- A branch with the name of the folder. Git cannot hold a branch
dependabotand a branchdependabot/nuget/…at the same time, so the push of the second fails. A 2021 Dependabot report fixed TF401398 by deleting the branch nameddependabot. - 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
- Look both names up as above.
- The source is missing: push it (
git push -u origin <branch>) and read the push output; a refused push leaves no branch. - The target is missing: choose a target that is listed under Repos → Branches. The repository's default branch is marked there.
- 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 · 日本語