Could not find a 'develop' or 'master' branch, neither locally nor remotely on TeamCity with GitVersion tool.

Posted on
GitVersion TeamCity

The message “Could not find a ‘develop’ or ‘master’ branch, neither locally nor remotely.” occurs when you are running GitVersion and TeamCity (or any other CI server) doesn’t do full fetch on build agent.

Here’s full log from TeamCity agent:

[08:20:14][Step 1/1] INFO [08/01/18 8:20:14:01] Working directory: D:\BuildAgent\work\812fa41891c9d060\Build
[08:20:14][Step 1/1] INFO [08/01/18 8:20:14:01] IsDynamicGitRepository: False
[08:20:14][Step 1/1] INFO [08/01/18 8:20:14:07] Returning Project Root from DotGitDirectory: D:\BuildAgent\work\812fa41891c9d060\.git - D:\BuildAgent\work\812fa41891c9d060
[08:20:14][Step 1/1] INFO [08/01/18 8:20:14:07] Running on Windows.
[08:20:14][Step 1/1] INFO [08/01/18 8:20:14:07] Applicable build agent found: 'TeamCity'.
[08:20:14][Step 1/1] INFO [08/01/18 8:20:14:08] Branch from build environment: refs/heads/feature/tp128916-arb-loop-execution
[08:20:14][Step 1/1] INFO [08/01/18 8:20:14:26] IsDynamicGitRepository: False
[08:20:14][Step 1/1] INFO [08/01/18 8:20:14:26] Returning Project Root from DotGitDirectory: D:\BuildAgent\work\812fa41891c9d060\.git - D:\BuildAgent\work\812fa41891c9d060
[08:20:14][Step 1/1] INFO [08/01/18 8:20:14:26] Project root is: D:\BuildAgent\work\812fa41891c9d060
[08:20:14][Step 1/1] INFO [08/01/18 8:20:14:26] DotGit directory is: D:\BuildAgent\work\812fa41891c9d060\.git
[08:20:14][Step 1/1] INFO [08/01/18 8:20:14:26] IsDynamicGitRepository: False
[08:20:14][Step 1/1] INFO [08/01/18 8:20:14:26] Returning Project Root from DotGitDirectory: D:\BuildAgent\work\812fa41891c9d060\.git - D:\BuildAgent\work\812fa41891c9d060
[08:20:14][Step 1/1] INFO [08/01/18 8:20:14:27] Begin: Loading version variables from disk cache
[08:20:14][Step 1/1]   INFO [08/01/18 8:20:14:27] Cache file D:\BuildAgent\work\812fa41891c9d060\.git\gitversion_cache\FBADB48488205BA04AAC55568FD062A7682C9B49.yml not found.
[08:20:14][Step 1/1] INFO [08/01/18 8:20:14:27] End: Loading version variables from disk cache (Took: 2.01ms)
[08:20:14][Step 1/1] INFO [08/01/18 8:20:14:27] IsDynamicGitRepository: False
[08:20:14][Step 1/1] INFO [08/01/18 8:20:14:27] Returning Project Root from DotGitDirectory: D:\BuildAgent\work\812fa41891c9d060\.git - D:\BuildAgent\work\812fa41891c9d060
[08:20:14][Step 1/1] INFO [08/01/18 8:20:14:28] Using latest commit on specified branch
[08:20:14][Step 1/1] INFO [08/01/18 8:20:14:29] Begin: Attempting to inherit branch configuration from parent branch
[08:20:14][Step 1/1]   INFO [08/01/18 8:20:14:30] Begin: Finding branch source
[08:20:14][Step 1/1]   INFO [08/01/18 8:20:14:30] End: Finding branch source (Took: 4.00ms)
[08:20:14][Step 1/1]   INFO [08/01/18 8:20:14:31] Begin: Getting branches containing the commit 'd885462c8b010b91982034f2a59c71b2c624f2b7'.
[08:20:14][Step 1/1]     INFO [08/01/18 8:20:14:31] Trying to find direct branches.
[08:20:14][Step 1/1]     INFO [08/01/18 8:20:14:31] No direct branches found, searching through tracked branches.
[08:20:14][Step 1/1]   INFO [08/01/18 8:20:14:31] End: Getting branches containing the commit 'd885462c8b010b91982034f2a59c71b2c624f2b7'. (Took: 0.00ms)
[08:20:14][Step 1/1]   INFO [08/01/18 8:20:14:31] Found possible parent branches: 
[08:20:14][Step 1/1] INFO [08/01/18 8:20:14:31] End: Attempting to inherit branch configuration from parent branch (Took: 23.01ms)
[08:20:14][Step 1/1] ERROR [08/01/18 8:20:14:32] An unexpected error occurred:
[08:20:14][Step 1/1] System.InvalidOperationException: Could not find a 'develop' or 'master' branch, neither locally nor remotely.
[08:20:14][Step 1/1]    at GitVersion.BranchConfigurationCalculator.InheritBranchConfiguration(Boolean onlyEvaluateTrackedBranches, IRepository repository, Commit currentCommit, Branch currentBranch, KeyValuePair`2 keyValuePair, BranchConfig branchConfiguration, Config config, IList`1 excludedInheritBranches)
[08:20:14][Step 1/1]    at GitVersion.BranchConfigurationCalculator.GetBranchConfiguration(Commit currentCommit, IRepository repository, Boolean onlyEvaluateTrackedBranches, Config config, Branch currentBranch, IList`1 excludedInheritBranches)
[08:20:14][Step 1/1]    at GitVersion.GitVersionContext.CalculateEffectiveConfiguration()
[08:20:14][Step 1/1]    at GitVersion.GitVersionContext..ctor(IRepository repository, Branch currentBranch, Config configuration, Boolean onlyEvaluateTrackedBranches, String commitId)
[08:20:14][Step 1/1]    at GitVersion.ExecuteCore.<>c__DisplayClass6_0.<ExecuteInternal>b__0(IRepository repo)
[08:20:14][Step 1/1]    at GitVersion.GitPreparer.WithRepository[TResult](Func`2 action)
[08:20:14][Step 1/1]    at GitVersion.ExecuteCore.ExecuteGitVersion(String targetUrl, String dynamicRepositoryLocation, Authentication authentication, String targetBranch, Boolean noFetch, String workingDirectory, String commitId, Config overrideConfig)
[08:20:14][Step 1/1]    at GitVersion.SpecifiedArgumentRunner.Run(Arguments arguments, IFileSystem fileSystem)
[08:20:14][Step 1/1]    at GitVersion.Program.VerifyArgumentsAndRun()

How to solve it?

Edit build configuration and add first step which will fetch whole tree for GitVersion.

  1. Click Edit Configuration Settings
  2. Click Build Steps on right side
  3. Click Add Build Step as first step
  4. Select Command Line as runner type
  5. To Custom script add ”%env.TEAMCITY_GIT_PATH%” fetch –progress origin %vcsroot.branch%
Could not find a 'develop' or 'master' branch, neither locally nor remotely on TeamCity with GitVersion tool. /images/could-not-find-a-develop-or-master-branch.png

Read more about the issue “Could not find a ‘develop’ or ‘master’ branch, neither locally nor remotely.” and other solutions on https://github.com/GitTools/GitVersion/issues/912