Skip to content

Instantly share code, notes, and snippets.

@lucasdinonolte
Created November 5, 2012 09:45
Show Gist options
  • Save lucasdinonolte/4016361 to your computer and use it in GitHub Desktop.
Save lucasdinonolte/4016361 to your computer and use it in GitHub Desktop.
Copy current git branch to clipboard
git branch | grep "*" | awk '{ print $2 }' | pbcopy
@MSPigl
Copy link

MSPigl commented Jun 9, 2021

@smithtimmytim that one removed any "n" chars from my copied branch name.

@Hoijof
Copy link

Hoijof commented Oct 22, 2021

@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 😅 )

@JoA-MoS
Copy link

JoA-MoS commented May 4, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment