title: How to get a branch name with a slash in Azure DevOps?
body: <p>Azure Devops offers two variables containing information about the current git branch name: <code>$(Build.SourceBranchName)</code> and <code>$(Build.SourceBranch)</code>.</p>
  
  <p>While <code>SourceBranch</code> contains the full reference to the branch, <code>SourceBranchName</code> is expected to contain only the short branch name. </p>
  
  <p>Unfortunately, the behavior is a bit unexpected when the branch name contains a slash (<code>/</code>):</p>
  
  <pre><code>+---------------------------------------------------------------------------------------------------------+
  | Situation                     | Git branch name  | Build.SourceBranch          | Build.SourceBranchName |
  |---------------------------------------------------------------------------------------------------------|
  | branch name contains no slash | mybranch         | refs/heads/mybranch         | mybranch               |
  | branch name contains slash    | release/mybranch | refs/heads/release/mybranch | mybranch               |
  +---------------------------------------------------------------------------------------------------------+
  </code></pre>
  
  <p>The part of the branch name before the slash is not considered as part of the branch name. My colleague pointed out that this is the <a href="https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&amp;tabs=yaml" rel="noreferrer">documented behavior of Azure Devops</a>:</p>
  
  <blockquote>
    <p>Git repo branch or pull request: The last path segment in the ref. For example, in refs/heads/master this value is master. In refs/heads/feature/tools this value is tools.</p>
  </blockquote>
  
  <p>I am not sure if this behavior is particularly useful: I want to checkout the branch, and need the branch name to <em>include</em> the slash. Also, If the part before the slash is stripped off, there might well be confusion about the actual path, as the name could be ambiguous.</p>
  
  <p>I need the branch name <em>including</em> the slash. Is there any simple way to get it? Do I always have to work with the full ref in order to be on the safe side?</p>