-
-
Save lucasdinonolte/4016361 to your computer and use it in GitHub Desktop.
| git branch | grep "*" | awk '{ print $2 }' | pbcopy |
just for anyone using bash for Windows, here's their equivalent command:
git branch | grep '^\*' | cut -d' ' -f2 | tr -d '\n' | clip
Bash for windows has some but not all of the Linux commands installed, and pbcopy is one of those which it doesn't have.
As of Git 2.22 just:
git branch --show-current | pbcopyLooks like that last one still needs the newline removed
git branch --show-current | tr -d '\n' | pbcopy@smithtimmytim that one removed any "n" chars from my copied branch name.
@smithtimmytim that one removed any "n" chars from my copied branch name.
@MSPigl You probably did tr -d 'n' instead of tr -d '\n'. (Probably he updated his comment fixing that 😅 )
for those who end up here after today, there is a command built into git to show the current branch
git branch --show-current
Add these get aliases to your .gitconfig and you have the same functionality
[alias]
scb = branch --show-current
ccb = ! git scb | tr -d '\n' | pbcopy
git scb - shows (prints) current branch
git ccb - copies the current branch to clipboard
I used this variant: