Skip to content

Instantly share code, notes, and snippets.

@raine
Created February 27, 2015 10:12
Show Gist options
  • Save raine/e91a245a61f2e73be739 to your computer and use it in GitHub Desktop.
Save raine/e91a245a61f2e73be739 to your computer and use it in GitHub Desktop.
git add with grep
[alias]
grep-add = "!sh -c 'git ls-files -m -o --exclude-standard | grep $1 | xargs git add' -"
grep-add-patch = "!sh -c 'git add -p `git ls-files -m -o --exclude-standard | grep $1`' -"
alias gga='git grep-add'
alias ggap='git grep-add-patch'
@raine
Copy link
Author

raine commented Feb 27, 2015

single alias for git add -p with and without grep

# enable single alias for both git add -p and grep + git add -p 
function git-add-patch; {
  if (( $# == 0 )); then
    git add -p
  else
    git grep-add-patch $1
  fi;
}

alias gap='git-add-patch'
$ gap pattern
$ gap

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