unixorn/git-extra-commands

View on GitHub
bin/git-copy-branch-name

Summary

Maintainability
Test Coverage
#!/usr/bin/env bash
#
# Copy the current branch name to the clipboard, or stdout if not on macOS

branch=$(git rev-parse --abbrev-ref HEAD)

if [[ "$(uname -s)" = "Darwin" ]]; then
  echo "$branch" | tr -d '\n' | tr -d ' ' | pbcopy
else
  echo "$branch"
fi