I’ve been using git for various projects and want to share tips for making it more convenient.
One of git’s advantages is cheap branches. A branch is just a file in .git/refs/heads containing the id of the last commit, so creating a new branch takes very little time. With such capabilities, most programmers use branches extensively.
Whatever model you choose for branches, you can eventually forget which branch you’re on and commit code to the wrong place. Although this is easily fixed, you can avoid it by adding branch information to your bash prompt.
Installing git bash completion
Git includes several useful scripts, including git-completion.bash. After loading it, bash completion will include git commands, local and remote branch names, tags, and more. The script also defines useful functions for getting environment information.
% git
add -- add file contents to index
am -- apply patches from a mailbox
apply -- apply patch to files and/or to index
archimport -- import an Arch repository into git
archive -- create archive of files from named tree
bisect -- find, by binary search, change that introduced a bug
blame -- show what revision and author last modified each line of a file
br -- alias for 'branch'
branch -- list, create, or delete branches
bundle -- move objects and refs by archive
cat-file -- provide content or type information for repository objects
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
</pre>
If you use MacPorts, ensure git-core is installed with the +bash_completion variant:
% sudo port install git-core +bash_completion
---> Computing dependencies for git-core
---> Cleaning git-core
If you installed git from source, search for the script:
**Update:** Enclose colors in PS1 with [], otherwise bash will incorrectly calculate prompt length and handle line wrapping incorrectly.
After setup, if the current directory is under git control, the command line will display the current branch name.
At the 2011 Pycon.UA conference, I presented on speeding up development with virtualized dev environments using VagrantUp and Fabric.
Virtualization lets de...
I often need project version information for documentation, About boxes, or website footers. Instead of hardcoding version numbers, I let git provide them au...
The limited console settings in Windows annoy many users. In particular, the font selection is limited to Consolas, Lucida Console, and vague “Raster Fonts.”...
Everyone who works on multiple computers faces the problem of unifying personal environment settings. When working in *nix/linux, you quickly develop your ow...
Comments