Saturday, October 31, 2015

Installing and setting up Git for Mac OSX

Having been out of the weeds on the technical stuff for a couple years, I decided to document my journey in building a OCR reader app. The first step in that was to find a code repository to store all the stuff as I build it out.
I've used subversion, CVS and Perforce in the past for work and git for fun in the past (on Linux). I figured I'd go with Git but since I've moved to Mac OSX a few years ago, here is the dump of what it takes to get set up:

1. Git comes preinstalled on a Mac running OSX 10.6 or newer. Type “git” in a terminal to confirm or to install.
2. Check the version “git —version” and compare against the latest here:
3. If older, then download .dmg and install it.
4. Restart terminal and run “git —version” again to confirm new version.
5. Set up your identity for commits:
    Last login: Sat Oct 31 11:32:25 on ttys002
Anils-MacBook-Air:~ anilmurty$ git --version
git version 2.6.2
Anils-MacBook-Air:~ anilmurty$ git config --global "Anil Murty"
Anils-MacBook-Air:~ anilmurty$ git config --global

6. Set up default text editor. For Mac: Vim, Emacs or TextWrangler are good options. I've used vi and emacs on linux so I decided to try something new and use TextWrangler this time. TextWrangler does not have command line tools by default so you may have to install them, alternatively if you just wish to open files from the command line and then use the GUI, you can modify your .bash_profile file and add a line:
Add this to your .bash_profile file under your user directory on Mac OS X (e.g “/users/anilmurty")
# Type 'tw' on the terminal to open TextWrangler
alias tw='open -a /Applications/'
Then set tw as the default editor for git:
Anils-MacBook-Air:~ anilmurty$ git config --global core.editor tw

7. Check all your config settings:

Anils-MacBook-Air:~ anilmurty$ git config --list
core.pager=less -r
alias.a=!git add . && git status!git add -u . && git status
alias.aa=!git add . && git add -u . && git status
alias.c=commit -m --amend!git add . && git commit
alias.acm=!git add . && git commit -m
alias.l=log --graph --all --pretty=format:'%C(yellow)%h%C(cyan)%d%Creset %s %C(white)- %an, %ar%Creset'
alias.ll=log --stat --abbrev-commit
alias.lg=log --color --graph --pretty=format:'%C(bold white)%h%Creset -%C(bold green)%d%Creset %s %C(bold green)(%cr)%Creset %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
alias.llg=log --color --graph --pretty=format:'%C(bold white)%H %d%Creset%n%s%n%+b%C(bold blue)%an <%ae>%Creset %C(bold green)%cr (%ci)' --abbrev-commit
alias.master=checkout master
alias.spull=svn rebase
alias.spush=svn dcommit
alias.alias=!git config --list | grep 'alias\.' | sed 's/alias\.\([^=]*\)=\(.*\)/\1\ => \2/' | sort
credential.helper=osxkeychain Murty core.editor=tw

Anils-MacBook-Air:~ anilmurty$