Skip to content

Instantly share code, notes, and snippets.

@andrewmriley
Last active April 23, 2024 18:19
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save andrewmriley/6401eef48859519f483c to your computer and use it in GitHub Desktop.
Save andrewmriley/6401eef48859519f483c to your computer and use it in GitHub Desktop.
Copy your current git branch name to clipboard
## Choose one and add it as an alias or throw it in a script ##
### Modern Git Thanks to @Pezmc
# Linux/Unix Wayland
git branch --show-current | wl-copy
# Linux/Unix X11
git branch --show-current | xclip -selection clipboard
# MacOS
git branch --show-current | pbcopy
### Pre Git 2.22
# linux/unix
git rev-parse --abbrev-ref HEAD | tr -d '\n' | xclip -selection clipboard
# os x
git rev-parse --abbrev-ref HEAD | tr -d '\n' | pbcopy
@keriati
Copy link

keriati commented May 18, 2018

thanks

@Pezmc
Copy link

Pezmc commented Oct 21, 2020

As of Git 2.22 just:

git branch --show-current | pbcopy

@HCaetano
Copy link

This is very useful

@danielbellmas
Copy link

Thanks @Pezmc 🙏

@uship-elon
Copy link

thanks

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