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?
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.
3
u/DanLynch Apr 12 '15
git grep can also search multiple commits/branches/whatever, not just your working tree.
1
u/mus1Kk Apr 14 '15
I reckon, git's version is faster. But being shocked about that is a bit melodramatic...
1
u/ebneter Apr 13 '15
I have a bunch of aliases defined that I rarely use, but which are handy for doing occasional complex tasks. Obviously I don't remember them, but I can look at them quickly since they're well-commented and find the one I need.
That's frankly almost the only use I have for aliases in git.
1
u/listaks Apr 13 '15
I use a set of aliases based on the ones in zprezto. The nice thing about them is that they unify related commands together in a consistent naming scheme. For example, actions manipulating the index are all prefixed gi, so you have gia to stage changes, gir to unstage changes, gid to see the diff of staged changes, and gix to stage file deletions, rather than git add, git reset, git diff --cached, and git rm --cached. This helps cover up the inconsistencies in standard git commands, as well as makes the mnemonics easier to remember.
Some of my most frequently used aliases:
alias gc='git commit --verbose'
alias gca='git commit --verbose --all'
alias gcA='git commit --verbose --amend'
# git-fetch-merge
alias gfm='git pull --verbose --stat --ff-only'
# git-fetch-rebase
alias gfr='git pull --verbose --stat --rebase
# git-index-diff: Show staged changes.
alias gid='git diff --cached'
# git-worktree-diff: Show changes *since* last commit.
alias gwd='git diff HEAD"
# Show changes *in* last commit.
alias gwD='git diff HEAD~1'
# git-worktree-status
alias gws='git status --short'
alias gl='git log --topo-order --decorate=short'
# git-log-remote: Show unpulled commits in the remote repo
alias glr='gl '\''@..@{upstream}'\'
# git-log-local: Show unpushed commits in the local repo
alias gll='gl '\''@{upstream}..@'\'
# git-log-local-remote: Show unpushed *and* unpulled commits.
alias gllr='gl --left-right '\''@...@{upstream}'\'1
u/gfixler Apr 14 '15
# git-worktree-diff: Show changes *since* last commit. alias gwd='git diff HEAD"That's the same as
git diff.# Show changes *in* last commit. alias gwD='git diff HEAD~1'This doesn't show changes in the last commit. It shows changes between the parent of the current commit and your working tree.
11
u/[deleted] Apr 12 '15
Seems kind of terrible to me. 'git pull' and 'git push' really doesn't take much time to type. But you're adding unnecessary cognitive load by using non-standard terms.
The time it will take to learn and remember all the shortcuts is not worth it. Typing something out is not that difficult. If I even once have to go look up a shortcut because I forgot it, that will already take the same amount of time it would to type out 'git rebase master' 20 times. Add to that that it will break my chain of thought and waste another 5 minutes, and just make me more tired than I need to be. Not to mention creating all the aliases. Terrible return on time investment.