Posted By

machacks on 03/10/12


Tagged


Versions (?)

(BREW) Git tricks, tips and workflows


 / Published in: Bash
 

  1. # Git Autocompletion for your shell
  2.  
  3. # 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:
  4.  
  5. source `brew --prefix git`/etc/bash_completion.d/git-completion.bash
  6.  
  7. # 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.
  8.  
  9. # Bash-completion is also available via Mac Ports
  10.  
  11. brew install bash-completion
  12.  
  13. # To use bash_completion, add the following lines at the end of your .bash_profile:
  14.  
  15. if [ -f /opt/local/etc/bash_completion ]; then
  16. . /opt/local/etc/bash_completion
  17. fi
  18.  
  19. # and also available via fink (for the ancient types)
  20.  
  21. bash-completion 20060301-3 Command-line completions for bash
  22.  
  23.  
  24. # 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):
  25.  
  26. # Enable bash completion for git
  27. # This allows git-completion to work properly
  28.  
  29. source `brew prefix`/etc/git-completion.d
  30.  
  31. # 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).
  32.  
  33. # If your version of ZSH is older, you can download the git completion from the ZSH repository (h/t graywh on Hacker News)
  34. # Alias git to ‘g’
  35. # I also alias git to g, saving me 66% on typing time! Also, I’m lazy. Add the following to your .bashrc or .zshrc:
  36.  
  37. alias g='git'
  38.  
  39. # 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:
  40.  
  41. # Autocomplete for 'g' as well
  42.  
  43. complete -o default -o nospace -F _git g
  44.  
  45. git-config(1)
  46.  
  47. # 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:
  48.  
  49. git config --global user.name "machacks"
  50. git config --global user.email "[email protected]"
  51.  
  52. # 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.
  53.  
  54. # 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:
  55.  
  56. # Allow all Git commands to use colored output, if possible
  57.  
  58. git config --global color.ui auto
  59.  
  60. # Disable the advice shown by Git when you attempt to push something that’s not fast forward-able
  61.  
  62. git config --global advice.pushNonFastForward false
  63.  
  64. # Disable “how to stage/unstage/add” hints given by git status:
  65.  
  66. git config --global advice.statusHints false
  67.  
  68. # Tell Git which whitespace problems it should recognize, namely any whitespace at the end of a line, as well as mixed spaces and tabs:
  69.  
  70. git config --global core.whitespace trailing-space,space-before-tab
  71.  
  72. # See the man page for more possible options on this.
  73.  
  74. # Allow git diff to do basic rename and copy detection:
  75.  
  76. git config --global diff.renames copies
  77.  
  78. # Tell git diff to use mnemonic prefixes (index, work tree, commit, object) instead of the standard a and b notation:
  79.  
  80. git config --global diff.mnemonicprefix true
  81.  
  82. # When branching off a remote branch, automatically let the local branch track the remote branch:
  83.  
  84. git config --global branch.autosetupmerge true
  85.  
  86. # When pushing without giving a refspec, push the current branch to its upstream branch. See the git config man page for more possible options.
  87.  
  88. git config --global push.default tracking
  89.  
  90. # Enable the recording of resolved conflicts, so that identical hunks can be resolved automatically later on.
  91.  
  92. git config --global rerere.enabled true
  93.  
  94. # You may also want to investigate the rerere.autoupdate setting.
  95.  
  96. # Always show a diffstat at the end of a merge:
  97.  
  98. git config --global merge.stat true
  99.  
  100. # 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.
  101.  

Report this snippet  

You need to login to post a comment.