From 897bdb23d15b89c16a05608deaead004ac0bf250 Mon Sep 17 00:00:00 2001 From: Isabelle Viktoria Maciohsek Date: Sun, 4 Apr 2021 21:50:46 +0300 Subject: [PATCH] Add current branch name --- snippets/current-branch-name.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 snippets/current-branch-name.md diff --git a/snippets/current-branch-name.md b/snippets/current-branch-name.md new file mode 100644 index 000000000..6aac16ff9 --- /dev/null +++ b/snippets/current-branch-name.md @@ -0,0 +1,17 @@ +--- +title: Get the current branch name +tags: branch,beginner +--- + +Prints the current branch name. + +- Use `git rev-parse --abbrev-ref HEAD` to print the name of the current branch. + +```sh +git rev-parse --abbrev-ref HEAD +``` + +```sh +git checkout patch-1 +git rev-parse --abbrev-ref HEAD # Prints `patch-1` +```