Skip to content

Instantly share code, notes, and snippets.

@fengshuo
Forked from lucasdinonolte/gist:4016361
Last active March 15, 2017 23:33
Show Gist options
  • Save fengshuo/b0fe2721cbc0f6cae2ac380c4596cb8f to your computer and use it in GitHub Desktop.
Save fengshuo/b0fe2721cbc0f6cae2ac380c4596cb8f to your computer and use it in GitHub Desktop.
Copy current git branch to clipboard
For those, who don't know how to make this work: create a file, e.g. git_branch_name_to_clipboard.sh in your user directory with following content:
`git branch | grep "*" | awk '{ print $2 }' | pbcopy`
or use this to remove the new line when you paste:
`git branch | grep "*" | awk '{ print $2 }' | tr -d '\n' | pbcopy`
Then in `.gitconfig file`, which is located in your user folder, add these lines under [alias]:
`cp = "!sh $HOME/git_branch_name_to_clipboard.sh"`
Now performing git cp will copy your current branch name to clipboard.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment