But its interface was clearly designed by programmers. Its configuration almost makes up for this.
Almost.
It helps to stay up-to-date, though. Things keep getting better with each release.
brew update brew upgrade git
It also makes sense to keep your ~/.gitconfig in ~/Dropbox elsewhere shared among your computers.
You should keep all your dotfiles there or a Git project, but that's a topic for another day.
You're going to type git a lot throughout the day. Why not make it a little easier?
Put this in your .bashrc, .profile, or wherever:
alias g=git
Now you'll just need to type g to use Git: e.g., g config, g commit, and g clone.
You should make simple-to-remember aliases for all commands you type frequently throughout the day. Some examples:
be for bundle execpsg for ps aux | grept for bundle exec rake testtu, tf, and ti to run unit, functional, and integration tests are left as an excercise for the reader
You've already got one in ~/.gitconfig for global settings
and .git/config in any Git project.
g config --list to see all of the current settings.
g config --list --global to see just the settings from ~/.gitconfig.
g config --list --local to see just the settings from .git/config.
Add or update values with g config --global foo.bar baz to set foo.bar to baz.
g help config gives a fairly exhaustive list of available configuration options.
Enable these settings by prefixing with g config --global.
color.ui autopush.default trackingdiff.tool opendiffmerge.tool opendiffdifftool.prompt falsemergetool.prompt falseformat.pretty '%Cred%h%Creset %aN -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset'8bc36cb Patrick Byrne - (origin/master, origin/HEAD, master) Update to new shared DB IP address (9 days ago)core.autocrlf inputrerere.enabled trueThis is where you really make Git your own. Create custom commands to do exactly what you want.
alias.co checkout
Essentially a find and replace. g co master expands to g checkout master.
alias.dm '!git diff | mate'
Aliases prefixed with with a bang are performed as if you'd typed them into the shell. This lets you perform more complex interactions with Git.
To make your most frequently used commands (e.g., push,
pull, commit, merge,
checkout, diff) even quicker and easier to type (e.g., p,
u, c, m,
co, d).
To make less frequently used commands easier to remember. For example,
edit the last commit with g amend instead of g commit
--amend or view everything about a specific commit with
g details 43344a2 instead of log -n1 -p
--format=fuller 43344a2
To allow for more complex functionality, not available within Git
itself. View a list of commit messages (changelog-style) between two
SHAs, branches, or tags with g changes master production
by adding this alias: alias.changes "!f() { git log
--pretty=format:'* %s' $1..$2; }; f"
alias.a addalias.aa 'add .'alias.c commitalias.cm 'commit -m'alias.co checkoutalias.d diffalias.dc 'diff --cached'alias.dcm 'diff --cached | mate'alias.dm 'diff | mate'alias.lg 'log --graph --abrev-commit --date=relative'alias.p pushalias.s statusalias.u pullalias.ur 'pull --rebase'alias.amend 'commit --amend'alias.ammend 'commit --amend'alias.br branchalias.brs 'branch -a'alias.branchname '!git branch | grep "^*" | awk '{ print $2 }''alias.changes '!f() { git log --pretty=format:"* %s" $1..$2; }; f'alias.deleted 'ls-files --deleted'alias.details 'log -n1 -p --format=fuller'alias.ff '!git fetch && git wtf'alias.mergeupstream '!git fetch upstream && git merge upstream/master master'alias.searchlogs '!git log --oneline | grep'alias.today 'log --stat --since="1 Day Ago" --graph --pretty=oneline --abbrev-commit --date=relative'alias.unstage 'reset HEAD'
Autocompletes branch names and commands by typing a few characters and hitting Tab. Simple(ish) to implement, too.
Install bash-completion:
brew install bash-completion
And then add this to your Bash config to load completion scripts from Homebrew packages:
[ -f `brew --prefix`/etc/bash_completion ] && . `brew -- prefix`/etc/bash_completion
And enable completion for your g alias in addition to git:
complete -o default -o nospace -F _git g
Another great part of Git’s completion is the __git_ps1 function. It spits out information about your Git repository, useful for putting in your $PS1 (your shell prompt).
\w $(rvm-prompt i v 2> /dev/null)\[\e[1m\] $(__git_ps1 2> /dev/null)\[\e[0m\] \n$
~/workspace/ngin ree-1.8.7 (master $=) $
Configurable with environment variables.
GIT_PS1_SHOWDIRTYSTATE=1 to show * if there are unstaged changes and + if staged
and uncommitted changes.
GIT_PS1_SHOWSTASHSTATE=1 to show $ if there are stashed changes.
GIT_PS1_SHOWUNTRACKEDFILES=1 to show % if there are untracked files.
GIT_PS1_SHOWUPSTREAM=1 to show < if there are unpulled changes, > if there are unpushed changes, <> if there are both, or = if everything’s synced.
Emulates Mercurial’s hg incoming and hg
outgoing commands. showing you unpushed commits and fetched
commits which aren't yet merged. When __git_ps1 shows you
> or <, g wtf gives you
some more details.
Download from http://gitorious.org/willgit/mainline/blobs/master/bin/git-wtf and put it somewhere in your $PATH.
A nice third-party set of additional Git commands. Nothing life-changing, but some improved quality-of-life. For more details, check out its GitHub project page.
brew install git-extras
g alias to view and add aliases.
g alias to view all aliases.
g alias foo to view all aliases matching 'foo'.
g alias foo bar to set the foo alias to bar.
g delete-branch foo to delete foo both locally and remotely.
g ignore to view and add patterns to the project’s .gitignore file.
g ignore to view all ignored patterns.
g ignore foo to add foo to .gitignore.
That’s about all I use, but there's loads more.
/
#