# How to know about current git branch in preset

**URL:** <https://discourse.cmake.org/t/how-to-know-about-current-git-branch-in-preset/7807>\
**Category:** Code\
**Created:** [April 1, 2023, 8:02pm UTC](https://discourse.cmake.org/t/how-to-know-about-current-git-branch-in-preset/7807 "2023-04-01T20:02:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![eriols](https://discourse.cmake.org/user_avatar/discourse.cmake.org/eriols/32/945_2.png) [@eriols](https://discourse.cmake.org/u/eriols)\
**Post date:** [April 1, 2023, 8:02pm UTC](https://discourse.cmake.org/t/how-to-know-about-current-git-branch-in-preset/7807/1 "2023-04-01T20:02:20Z")

</div>

I’ve had a shell script for local builds that I was hoping to sunset in favour of a `CmakeUserPresets.json` and it works very well with the exception that this script sets the output dir based on the name of the current git branch (eg `_build-my-branch`).  
Is there a good way to accomplish this with presets alone or would I need to do something like a wrapper around the cmake call putting this in an env variable perhaps?  
Thanks!

---

<div class="post-metadata">

**Author:** ![scivision](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/a87d85/32.png) [@scivision](https://discourse.cmake.org/u/scivision)\
**Post date:** [April 2, 2023, 11:36pm UTC](https://discourse.cmake.org/t/how-to-know-about-current-git-branch-in-preset/7807/2 "2023-04-02T23:36:17Z")

</div>

You would need a wrapper and env var with the preset

---

<div class="post-metadata">

**Author:** ![hamidelmaazouz](https://discourse.cmake.org/user_avatar/discourse.cmake.org/hamidelmaazouz/32/5590_2.png) [@hamidelmaazouz](https://discourse.cmake.org/u/hamidelmaazouz)\
**Post date:** [May 30, 2025, 1:55am UTC](https://discourse.cmake.org/t/how-to-know-about-current-git-branch-in-preset/7807/3 "2025-05-30T01:55:35Z")

</div>

Could you elaborate more @scivision ? I am facing as similar situation, where the presets almost always follow a git ref, and it’d be great to automate preset selection based on the current branch name ?
