7. Git Tools
10. Git Internals
A1.5 Appendix A: Git in Other Environments - Git in Zsh
Git in Zsh
Git also ships with a tab-completion library for Zsh.
contrib/completion/git-completion.zsh to your home directory and source it from your
Zsh’s interface is a bit more powerful than Bash’s:
$ git che<tab> check-attr -- display gitattributes information check-ref-format -- ensure that a reference name is well formed checkout -- checkout branch or paths to working tree checkout-index -- copy files from index to working directory cherry -- find commits not merged upstream cherry-pick -- apply changes introduced by some existing commits
Ambiguous tab-completions aren’t just listed; they have helpful descriptions, and you can graphically navigate the list by repeatedly hitting tab. This works with Git commands, their arguments, and names of things inside the repository (like refs and remotes), as well filenames and all the other things Zsh knows how to tab-complete.
Zsh happens to be fairly compatible with Bash when it comes to prompt customization, but it allows you to have a right-side prompt as well.
To include the branch name on the right side, add these lines to your
setopt prompt_subst . ~/git-prompt.sh export RPROMPT=$'$(__git_ps1 "%s")'
This results in a display of the current branch on the right-hand side of the terminal window, whenever your shell is inside a Git repository. It looks a bit like this:
Zsh is powerful enough that there are entire frameworks dedicated to making it better. One of them is called "oh-my-zsh", and it can be found at https://github.com/robbyrussell/oh-my-zsh. oh-my-zsh’s plugin system comes with powerful git tab-completion, and it has a variety of prompt "themes", many of which display version-control data. An example of an oh-my-zsh theme. is just one example of what can be done with this system.