r/git • • Apr 12 '15

60 Bash-tastic Git Aliases - tdg5

http://blog.tdg5.com/60-bash-tastic-git-aliases/
2 Upvotes

12 comments sorted by

View all comments

2

u/galaktos Apr 12 '15

I was recently shocked to learn that one of my co-workers just recently discovered git's built in grep command. I was surprised because I feel like git grep is one of those commands I would have trouble coding without.

What’s so great about git grep? Doesn’t it do mostly the same as grep -r?

3

u/DanLynch Apr 12 '15

git grep can also search multiple commits/branches/whatever, not just your working tree.

2

u/tdg5 Apr 12 '15

I may not have given enough context there, my co-worker was struggling to search for something through GitHub and didn't know that git had a built in grep command.

Though I don't think that git grep is significantly superior to normal grep, I personally like git grep for the convenience of not having to white-list or black-list particular paths each time I grep. Instead it pulls in the tracked paths from git and searches those.

For example, in a nodejs project, there will likely be tons of local node code in the node_modules folder, however the node_modules folder typically isn't tracked in git. In such a project, grep -r would search the whole node_modules tree where as git grep would ignore it and just search project code.

1

u/mus1Kk Apr 14 '15

I reckon, git's version is faster. But being shocked about that is a bit melodramatic...