News for hackers. Stuff that matters.
Re:Ask HN: Can I see your scripts? by mijoharas on Monday August 15, 2022 @08:07AM (#32468620)
yep! all git subcommands are separate binaries. Check out `ls /usr/lib/git-core` (that's the path on my machine). Or you can `locate git-add` or something to check where they're located on your machine. I have a tiny fzf script called `git select` to give me a nice interface for selecting branches I've recently worked on. Just call the script `git-select` and stick it somewhere in your path. In the spirit of this question, my one is here:

  !/bin/zsh

  alias git_my_branches="git for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'"

  local selected_branch=$(git_my_branches --color | fzf --ansi --tac | awk '{print $1}')
  if [ "$selected_branch" != '*' ]; then
          git checkout $selected_branch
  fi

There are no comments on this comment yet.