Squashing several Git commits into a single commit

This note shows how to merge an ugly feature branch with multiple dirty WIP commits back into the master as one pretty commit.

Squashing commits with git rebase

What we are describing here will destroy commit history and can go wrong. For this reason, do the squashing on a separate branch:

git checkout -b squashed_feature

This way, if you screw up, you can go back to your original branch, make another branch for squashing and try again.

Tip

If you didn't make a backup branch and something ...

Show the current Git branch on your Bash prompt

Append this to your ~/.bashrc:

export PS1='\[\033[01;32m\]\h\[\033[01;34m\] \w\[\033[31m\]$(__git_ps1 "(%s)") \[\033[01;34m\]$\[\033[00m\] '

Reload the changes by saying

source ~/.bashrc

For some customized prompts that also show the current Git prompt, see the examples section at the bottom of our bash prompt customizing card.

Typical .gitignore

log/*
tmp/*
storage/*
db/*.sqlite3
db/schema.rb
db/structure.sql
public/system
.project
.idea/
public/javascripts/all*
public/stylesheets/all*
public/stylesheets/*.css
config/database.yml
*~
*#*
.#*
.DS_Store
webrat-*.html
capybara-*.html
rerun.txt
coverage.data
coverage/*
dump_for_download.dump
.~lock.*
.*.swp
C:\\nppdf32Log\\debuglog.txt

Check out a remote branch in git

If you would like to checkout the branch groups, you can simply say this in recent versions of Git:

git fetch origin
git checkout groups

This will automatically track origin/groups from a local branch groups.

In older Git versions you need to say this:

git fetch origin
git checkout --track origin/groups

Configuring Git with .gitconfig

Basic configuration

Please keep this config simple. It should be a starting point for new developers learning Git.

[user]
  name = Your Name
  email = your.name@domain.com

[branch]
  sort = -committerdate
[color]
   ui = auto
[color "branch"]
  current = yellow reverse
  local = yellow
  remote = green
[color "diff"]
  whitespace = white reverse
  meta = blue reverse
  frag = blue reverse
  old = red
  new = green
[color "status"]
  added = green
  changed = yellow
  untracked = cyan
[interactive]
  singlekey = true # Do not requir...

Git for Subversion users

This is for people recovering from Subversion.

Get an existing from the server for the first time

git clone git@example.com:repositoryname

See what's changed

git status

Check in locally

git commit -m "good description"

Push local commits to the server

git push

Get and merge updates from the server

git pull

Stage a file for the next local commit

git add file

Stage all files for the next local commit

git add .

Create a new local branch and check it out

git checkout -b branchname

...

How to fix "Too many authentic authentication failures" with SSH and/or Capistrano

You are getting when connecting via SSH or deploying with Capistrano (which uses SSH):

Too many authentication failures for username

This is caused by having too many SSH keys added to your keyring or ssh-agent. Your ssh-agent will throw all keys against a server until one matches. Most servers will deny access after 5 attempts.

This issue might come and go as the order of the active SSH keys in your ssh-agent changes.

Quick fix

Have less keys. Up to 5 keys are fine when the SSHD you're connecting to is using the default ...

Slugs with FriendlyId

Gem to provide nice looking urls ("/blog/the-greatest-bug-i-never-fixed"). If you don't need anything too special (like i18n for the urls) it works as a drop-in-replacement. It basically overwrites #to_param to return the slug, and .find to search by the slug.

Make sure, everywhere you build paths, you use model_path(:id => model) instead of model_path(:id => model.id). You also need to adapt all code using something like .find_by_id. The regular .find is fine.

See the github README for installation instructions.

Don't forget ...

jcoglan's consent at master — GitHub

Consent is an access control abstraction layer for ActionController. It lets you restrict access to actions across your application using a single config file, rather than scattering access logic across your controllers using verify() and method-specific logic.

lib/rucksack_extras.rb at master from jamesu's rucksack — GitHub

Wrapper from Globalite API to the Rails 2.2 I18n API

Super-simple Ruby Subversion Command Line Wrapper — Agile Web Operations

I was setting up a Subversion repository one year ago. Of course, I also wanted to have regular backups of my Subversion repository. As I was tired of writing bash scripts for such a task, I looked into writing a simple Ruby script for backing up my Subversion repositories.

clemens's later_dude at master - GitHub

LaterDude is a small calendar helper with i18n support

jcapote's theman at master - GitHub

theman is a super simple "framework" that uses god/rufus-scheduler to create long running workers that do things at certain times.

leethal's live-validations at master - GitHub

Reads Active Record's validations and makes them available to live client side javascript

justinfrench's formtastic at master - GitHub

A Rails FormBuilder with semantically rich and accessible markup.

Updating Trac tickets in svn commits | tail -f findings.out

The ability to update and close Trac tickets associated with a given repo whenever a commit is made to that repo is pretty handy. No more committing, going to the Trac site, updating. I found several guides on setting this up floating around, this one being the most informative.

Heroku | How it Works

Heroku's architecture enables deployment with nothing but Git. Deployment is fast, simple, and just works – all you do is push code to your repo on Heroku.

pluginaweek's plugin_test_helper at master - GitHub

Simplifies plugin testing by creating an isolated Rails environment that simulates its usage in a real application

svenfuchs's rails-i18n at master - GitHub

Central point to collect locale data for use in Ruby on Rails.

rgrove's sanitize at master - GitHub

HTML sanitizer by the wonko.com guy.

Integrity | The easy and fun automated continuous integration server

Integrity is the angel watching over your shoulder while you code. As soon as you push your commits, it builds, runs your tests, and makes sure everything works fine.

sandofsky's acts_against_douchebar at master - GitHub

A Rails plugin that delivers a special message to DiggBar users, or runs frame-killer javascript.

mislav's hanna at master - GitHub

Hanna is an RDoc template that scales. It's implemented in Haml, making the sources clean and readable. It's built with simplicity, beauty and ease of browsing in mind.