mirror of
https://github.com/jbranchaud/til
synced 2026-01-02 22:58:01 +00:00
Add Get The Name Of The Current Branch as a git til
This commit is contained in:
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
|
||||
|
||||
For a steady stream of TILs, [sign up for my newsletter](https://tinyletter.com/jbranchaud).
|
||||
|
||||
_1103 TILs and counting..._
|
||||
_1104 TILs and counting..._
|
||||
|
||||
---
|
||||
|
||||
@@ -243,6 +243,7 @@ _1103 TILs and counting..._
|
||||
- [Excluding Files Locally](git/excluding-files-locally.md)
|
||||
- [Find The Date That A File Was Added To The Repo](git/find-the-date-that-a-file-was-added-to-the-repo.md)
|
||||
- [Find The Initial Commit](git/find-the-initial-commit.md)
|
||||
- [Get The Name Of The Current Branch](git/get-the-name-of-the-current-branch.md)
|
||||
- [Get The Short Version Of The Latest Commit](git/get-the-short-version-of-the-latest-commit.md)
|
||||
- [Grab A Single File From A Stash](git/grab-a-single-file-from-a-stash.md)
|
||||
- [Grep For A Pattern On Another Branch](git/grep-for-a-pattern-on-another-branch.md)
|
||||
|
||||
20
git/get-the-name-of-the-current-branch.md
Normal file
20
git/get-the-name-of-the-current-branch.md
Normal file
@@ -0,0 +1,20 @@
|
||||
# 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)
|
||||
Reference in New Issue
Block a user