22 December 2011

My Programming Reading List

I started collecting links to reading materials for programmers recently for my own use, but I realized it could be more generally useful. Checkout my list here, and check back often for updates:

Kevin’s Programming Reading List

07 December 2011

My Git Setup

Mostly for my own personal future reference, here is how I setup my Git environment.

Multiple Accounts

I love Git for source control, and it is a goal of mine to keep all of my personal projects on GitHub. That is easy enough, but for work, I also need to be able to use Git with two different accounts connecting to two different servers.

For this example, I am going to assume there are two accounts: a GitHub account associated with a personal email, and an account hosted on an imaginary GitDude service associated with a work email.

Step 1: Create RSA Keys
  1. Generate a key for GitHub:
    ssh-keygen -t rsa -C "personal_email@example.com"
  2. When prompted, choose the following location for your file to go:
    /Users/your_username/.ssh/id_rsa_github
  3. Follow instructions in the "Set up Git" section on  http://help.github.com/ to upload your public key to GitHub. On the same page, follow the instructions for setting your github.user and github.token config values.
  4. Generate a key for GitDude:
    ssh-keygen -t rsa -C "work_email@example.com"
  5. When prompted, choose the following location for your file to go:
    /Users/your_username/.ssh/id_rsa_gitdude
Step 2: Setup Config File
  1. Create a blank file called "config" in your ~/.ssh directory.
  2. Edit the file, and type the following text:

    Host gitdude.com
      HostName git.gitdude.com
      User git
      IdentityFile /Users/your_username/.ssh/id_rsa_gitdude
    
    Host github.com
      HostName github.com
      User git
      IdentityFile /Users/your_username/.ssh/id_rsa_github
Step 3: Setup User Name and Email

When using only one account on a computer, you can use global settings for user.name and user.email. However, when using two separate accounts, you need to use local settings for each repo. If you want to still use global settings, you will still need to use local settings for the repos that don't use the global credentials.
  • See this to get a list of all global settings:
    git config --global -l
  • Use this to set global git info:
    git config --global user.name "First Last"
    git config --global user.email "your_email@example.com"
  • Or this for local:
    git config --local user.name "First Last"
    git config --local user.email "your_email@example.com"
Same for github.user and github.token properties, if appropriate.

Step 4: Setup Default Editor

In order to write multiline commits, you will want to associate git with an editor:

    git config core.editor emacs

This allows you to make commits like "git commit". The editor will then open and allow you to enter a commit message.

References