# Get The Name Of The Current Branch

There are a couple ways of doing this. If you are on Git 2.22+, then the `git-branch` porcelain command now supports a flag for this.

```bash
$ git branch --show-current
main
```

If you are on an older version of Git or looking for a plumbing command that is more appropriate for scripting, then `git-rev-parse` is what you're looking for.

```bash
$ git rev-parse --abbrev-ref HEAD
main
```

[source](https://stackoverflow.com/questions/6245570/how-to-get-the-current-branch-name-in-git)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ploegert.gitbook.io/til/tools/git/get-the-name-of-the-current-branch.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
