/ Published in: Bash
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
# Git Autocompletion for your shell # I use Git primarily from the command line. Luckily, enabling the Git completion for both Bash and Zsh is quite easy if you used Homebrew to install Git. Simply add the following to your ~/.bashrc: source `brew --prefix git`/etc/bash_completion.d/git-completion.bash # If you got Git some other way, check if that includes the completion file. If not, you can always clone the git repo, and copy/link it from there. # Bash-completion is also available via Mac Ports brew install bash-completion # To use bash_completion, add the following lines at the end of your .bash_profile: if [ -f /opt/local/etc/bash_completion ]; then . /opt/local/etc/bash_completion fi # and also available via fink (for the ancient types) bash-completion 20060301-3 Command-line completions for bash # If you use Zsh, like me, there’s a bit more involved. Add the following to your ~/.zshrc (adjust as necessary for your installation method): # Enable bash completion for git # This allows git-completion to work properly source `brew prefix`/etc/git-completion.d # Update 2011-04-05: If you’re using a newer ZSH (I’ve tested this with 4.3.9), then you can skip all of the above, as Git completion will automagically work for you (if you already have autoload -U compinit && compinit in your .zshrc). # If your version of ZSH is older, you can download the git completion from the ZSH repository (h/t graywh on Hacker News) # Alias git to ‘g’ # I also alias git to g, saving me 66% on typing time! Also, I’m lazy. Add the following to your .bashrc or .zshrc: alias g='git' # Now, you’ll probably also want to have the Git Autocompletion when you’re using g as well. Add this to your .bashrc or .zshrc: # Autocomplete for 'g' as well complete -o default -o nospace -F _git g git-config(1) # In here, you can store all the global Git configuration settings. The .gitconfig file uses the INI file format to store settings, but you can also set (and get) all values by using git config. The most basic settings you should do are your name and eMail, both of which are included in every commit you make: git config --global user.name "machacks" # Not that I’m telling you how to run your life or anything, but you probably want use your own name and eMail address instead of mine. # Over time, you will accumulate your own set of configs that tweak Git to your liking. Here are a few of my settings that I find very useful: # Allow all Git commands to use colored output, if possible git config --global color.ui auto # Disable the advice shown by Git when you attempt to push something that’s not fast forward-able git config --global advice.pushNonFastForward false # Disable “how to stage/unstage/add†hints given by git status: git config --global advice.statusHints false # Tell Git which whitespace problems it should recognize, namely any whitespace at the end of a line, as well as mixed spaces and tabs: git config --global core.whitespace trailing-space,space-before-tab # See the man page for more possible options on this. # Allow git diff to do basic rename and copy detection: git config --global diff.renames copies # Tell git diff to use mnemonic prefixes (index, work tree, commit, object) instead of the standard a and b notation: git config --global diff.mnemonicprefix true # When branching off a remote branch, automatically let the local branch track the remote branch: git config --global branch.autosetupmerge true # When pushing without giving a refspec, push the current branch to its upstream branch. See the git config man page for more possible options. git config --global push.default tracking # Enable the recording of resolved conflicts, so that identical hunks can be resolved automatically later on. git config --global rerere.enabled true # You may also want to investigate the rerere.autoupdate setting. # Always show a diffstat at the end of a merge: git config --global merge.stat true # Now, you’ll notice that for each and every git config I used the --global option. The reason for that is that Git not only looks at your global gitconfig (located at ~/.gitconfig), but also a repository-specific config (.git/config). So you can customize all these settings for each of your repository to your liking, just run the git config command in your repository without the --global flag.