# Get the name of default branch

**URL:** <https://travis-ci.community/t/get-the-name-of-default-branch/12039>\
**Category:** Travis CI Discussions & Feedback\
**Tags:** github-integration\
**Created:** [August 31, 2021, 6:53am UTC](https://travis-ci.community/t/get-the-name-of-default-branch/12039 "2021-08-31T06:53:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![abitrolly](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/abitrolly/32/408_2.png) [@abitrolly](https://travis-ci.community/u/abitrolly)\
**Post date:** [August 31, 2021, 6:53am UTC](https://travis-ci.community/t/get-the-name-of-default-branch/12039/1 "2021-08-31T06:53:55Z")

</div>

Now that more repositories are using `main`, how to read the name of default branch during Travis builds? There is no such [environment variable](https://docs.travis-ci.com/user/environment-variables/#default-environment-variables).

---

<div class="post-metadata">

**Author:** ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)\
**Post date:** [August 31, 2021, 11:30am UTC](https://travis-ci.community/t/get-the-name-of-default-branch/12039/2 "2021-08-31T11:30:03Z")

</div>

> <https://stackoverflow.com/questions/28666357/git-how-to-get-default-branch>

---

<div class="post-metadata">

**Author:** ![abitrolly](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/abitrolly/32/408_2.png) [@abitrolly](https://travis-ci.community/u/abitrolly)\
**Post date:** [September 1, 2021, 5:37am UTC](https://travis-ci.community/t/get-the-name-of-default-branch/12039/3 "2021-09-01T05:37:09Z")

</div>

There accepted answer there is from 2017, when there was no hype with renaming `master` that required changes to `git` to be able to set the default branch. Is that really a recommended way in 2021?

---

<div class="post-metadata">

**Author:** ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)\
**Post date:** [September 1, 2021, 9:30am UTC](https://travis-ci.community/t/get-the-name-of-default-branch/12039/4 "2021-09-01T09:30:09Z")

</div>

What do you want to do? You asked how to get the default branch – I told you how to get the default branch. Default branch has been a feature in Git since its creation, nothing changed in the mechanism after the master → main renaming.

---

<div class="post-metadata">

**Author:** ![abitrolly](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/abitrolly/32/408_2.png) [@abitrolly](https://travis-ci.community/u/abitrolly)\
**Post date:** [September 1, 2021, 11:55am UTC](https://travis-ci.community/t/get-the-name-of-default-branch/12039/5 "2021-09-01T11:55:13Z")

</div>

You told me to go look at the page with many answers, and I am asking which answer should I choose?

---

<div class="post-metadata">

**Author:** ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)\
**Post date:** [September 1, 2021, 2:01pm UTC](https://travis-ci.community/t/get-the-name-of-default-branch/12039/6 "2021-09-01T14:01:53Z")

</div>

Whichever works for you the best.  
E.g. some show the default branch for the local repo, others for a remote repo.
