# Grepping in Git: How to Search Git Repository Revisions, Working Trees, Commit Messages, etc.

To search content of all tracked files in the current working tree for a pattern: git grep To search content of all commit messages for a pattern (‘-E’ for extended grep): git log [-E] --grep To search content of all commit diffs for lines that add or remove a pattern (‘-w’ for pattern only at word boundary): git [-w] log -G To search content of entire working trees of previous revisions for a pattern:

# gcd - A Git-aware cd Relative to the Repository Root with Auto-Completion

The following will enable you to have a Git-aware “cd” command with directory path expansion/auto-completion relative to the repository root. You will have to source it into your “~/.bashrc” file, after which invoking “gcd” from the shell will allow you specify directory paths relative to the root of your Git repository no matter where you are within the working tree. gcd() _gcd() " prev="2" dirnames=$(cd$TARGET; compgen -o dirnames $2) opts=$(for i in $dirnames; do if [[$i !

# Enhanced Git Log View Showing Symbolic References Associated With Each Commit

With multiple upstream repositories and branches, and different branches on different upstreams, an enhanced “log” view will help greatly in taking stock of everything. Adding the following line to your “~/.gitconfig” will give you a new command, “git slog” (for “short log”) that does just that: < p> # colorful 1-line log summary slog = log --pretty=format:'%Creset%C(red bold)[%ad] %C(blue bold)%h %Creset%C(magenta bold)%d %Creset%s %C(green bold)(%an)%Creset' --abbrev-commit --date=short This command will provide a colorful one-line summary of the project’s commit history, showing not only the commit date, SHA-1, commit message and author, but, most importantly in this context, an indication of the symbolic references associated with various commits in nice, bright [magenta].