Git: Switching back to the previous branch

Using git checkout - you can switch back to the branch you previously worked on.

(master) $ git checkout foobar
Switched to branch 'foobar'
(foobar) $ git checkout -
Switched to branch 'master'
(master) $

This also works with other commands like git merge:

(master) $ git checkout foobar
Switched to branch 'foobar'
(foobar) $ git merge -
Merged branch 'master'

git: How to forget a recorded resolution

If you recorded a bad fix for a conflict, you can tell git to forget that bad resolution:

git rerere forget your_file.rb

Afterwards, the badly resolved file will still be in your working directory. To get it back with confict markers, say:

git checkout -m your_file.rb

Resolve the conflict again, properly now. ;)

Trailer, a faster and easier way to deal with pull requests

Introducing Trailer from HouseTrip, a simple menu bar app that helps you manage your GitHub pull requests. It’s one feature we felt was lacking from our workflow!

Installing therubyracer and libv8 with Ruby 1.8 on OSX Mavericks

There seems to be no way to use therubyracer -v '0.11.4' and libv8 -v '3.11.8.17' on OS X Mavericks.

However, running bundle update therubyracer worked for me. It installed therubyracer -v '0.12.1' and libv8 -v '3.16.14.3' and I had not side effects.


Log of my attempts to get it working

Probably you got here when bundling failed building native extensions for therubyracer.

The libv8 (3.3.10.4) should have been installed when bundling. Unfortunately it is not building correctly on Mavericks, so the libv8.a f...

The new Modularity 2 syntax

We have released Modularity 2. It has many incompatible changes. See below for a script to migrate your applications automatically.

There is no does method anymore

We now use traits with the vanilla include method:

class Article < ActiveRecord::Base
  include DoesTrashable
end

When your trait has parameters, use square brackets:

class Article < ActiveRecord::Base
  include DoesStripFields[:name, :brand]
end

Note how you ...

How to set git user and email per directory

I am using git at several places: at work, at university, and at home. I want an own git user/email for each of those places, but I don't want to care setting the values each time I create or clone a new repository.

Git allows for setting user/email per repository, globally and system-wide, but I need a fourth dimension: per directory. By setting git environment variables using ondir, I managed to get exactly what I need.

  1. Install ondir (on a Mac: brew install ondir, other OSs need to install it from the linked page).
  2. Put these ...

HubSpot/mixen · GitHub

It's mixins (modules) for Coffeescript classes. Other than most homegrown approaches, this one allows you to keep using super.

safe_cookies is now in public beta

We proudly release our safe_cookies middleware into public beta and just published it on Github.

Features are:

  • make all application cookies secure and HttpOnly (keeping them from being sent over HTTP and protecting them from Javascript)
  • rewrite all client cookies once, making them secure and HttpOnly
  • notification if a request has unregistered cookies (no unsecure cookie will slip by)
  • ability to ignore external cookies, like __utma and other tracking cookies
  • easy configurat...

Speeding up ssh session creation

Establishing a new SSH connection usually takes only a few seconds, but if you’re connecting to a server multiple times in succession the overhead starts to add up. If you do a lot of Git pushing and pulling or frequently need to SSH to a dev server, you’ve probably felt the pain of waiting for SSH to connect so you can get back to doing work.

redshift

For all late night coders:

The program "redshift" changes your monitors' white balance according to your position on the planet and your local time. This is supposed to put less strain on your eyeballs than staring at a "daylight white" screen all day and night.
The program is in the Ubuntu repositories, so a simple "sudo apt-get install gtk-redshift" transfers it onto your hard drive.

I find the effect rather pleasing and so I have set the following alias on my computer:

alias rdshft='gtk-redshift -l 48.3714407:10.8982552 -t 6500:4200 &'...

Git & Mac: Working with Unicode filenames

I had some problems with Git and the file spec/fixtures/ČeskýÁČĎÉĚÍŇÓŘŠŤÚŮÝŽáčďéěíňóřšťúůýž. After pulling the latest commits, it would show that file as untracked, but adding and committing it would throw error: pathspec 'check in unicode fixture file once again' did not match any file(s) known to git.

Solution

Install Git version > 1.8.2 using homebrew and set

git config --global core.precomposeunicode true

Done.

Reason

According to the linked Stackoverflow post ...

... the cause is the different im...

Git: How to remove ignored files from your repository's directory

When you have files in your .gitignore they won't be considered for changes, but still you might want to get rid of them, e.g. because they clutter your file system.

While a regular git clean will ignore them as well, passing the -x switch changes that:

git clean -x

If you want to see what would happen first, make sure to pass the -n switch for a dry run:

git clean -xn

Clean even harder by passing the -f (force cleaning under certain circumstances; I think this is also required by default) or -d (removes director...

Automated "git bisect" will make your day

So you're hunting down a regression (or just a bug) and want to use git bisect to find out when it was introduced? Smart kid.
If you have a shell command ready to reveal if your current state is good or bad, you can have git do most of the work for you.

Using git bisect run <your command> you can tell git that your command will reveal the issue; git on the other hand will use the return value of that call to decide if the state is good or bad.
...

Sprites with Compass

Using CSS sprites for background images is a technique for optimizing page load time by combining smaller images into a larger image sprite.

There are ongoing arguments on how useful this still is, as modern browsers become more comfortable to load images in parallel. However, many major websites still use them, for example amazon, [facebook](...

Upgrading Rails 2 from 2.3.8 through 2.3.18 to Rails LTS

This card shows how to upgrade a Rails 2 application from Rails 2.3.8 through every single patch level up to 2.3.18, and then, hopefully, Rails LTS.

2.3.8 to 2.3.9

This release has many minor changes and fixes to prepare your application for Rails 3.

Step-by-step upgrade instructions:

  1. Upgrade rails gem
  2. Change your environment.rb so it says RAILS_GEM_VERSION = '2.3.9'
  3. Change your ...

asciidisco/Backbone.Mutators · GitHub

Backbone plugin to override getters and setters with logic.

git: How to always pull with rebase

In order to have more human readable git branches, do

  git pull --rebase

To always pull like this, write these lines to your ~/.gitconfig:

[pull]
   rebase = true

..or use this oneliner

git config --global pull.rebase true

Note that this will break if you pull from other upstream branches like

git pull origin other-branch

If you keep rebasing by default, you can get "merge pulls" like this:

git pull --no-rebase origin other-branch

marcandre/backports · GitHub

Essential backports that enable many of the nice features of Ruby 1.8.7 up to 2.0.0 for earlier versions.

Duplicate a git repository with all branches and tags

In order to clone a git repository including all branches and tags you need to use two parameters when cloning the old and pushing to the new repository respectively:

git clone --bare http://example.com/old-repo.git
cd old-repo
git push --mirror http://example.com/new-repo.git

Of course, the URLs to your repository might look different depending on the protocol used, username required, etc.
For a user git using the git protocol, it could be git@example.com:repository-namespace/repository.git

Use a global .gitignore file to ignore stuff from your machine

Sometimes you want git to ignore certain files that appear on your machine. You can do this in 3 ways:

  • Per project, in the project's .gitignore file
  • Per project, in a local exclude file
  • Globally on your machine

Downsides of per-project .gitignore entries

While it might be tempting to set it per project (other devs might benefit from it), you

  • need to do it each time for every project
  • "pollute" a project's .gitignore file with stuff...

Quick git contributors list

git shortlog -s -n [commit-range]

-n, --numbered
Sort output according to the number of commits per author

-s, --summary
Suppress commit descriptions, only provide commit count

[commit-range]
E.g. $tagname.. for "everything after that tag"

Example output for spreewald:

60  Tobias Kraze
12  Henning Koch
 7  Dominik Schöler
 6  Thomas Eisenbarth
 5  Martin Straub
 3  Minh Hemmer
 2  Alex McHale
 1  Manuel Kallenbach
 1  Andreas Robecke

#...

Git: How to show only filenames for a diff

When you want to do a git diff but do not care about the full diff and just want to know which files changed, use the --name-only switch:

$ git diff --name-only
app/controllers/sessions_controller.rb
app/models/user.rb
features/sign_in.feature

To include some brief information about changed lines, use the --stat switch:

$ git diff --stat
app/controllers/sessions_controller.rb |    8 +-
app/models/user.rb                     |   30 ++++
features/sign_in.feature               |  136 +++++++++++++++++

T...

Manage your AWS credentials for multiple accounts

Create a directory mkdir ~/.aws

Initialise git repository cd ~/.aws && git init

Create a git branch with a name you want (e.g. development for the aws development account credentials).

Add AWS credential file .aws_credentials:

AWSAccessKeyId=ABCDEFG1234
AWSSecretKey=4321GFEDCBA

Also add your EC2 cert and private key file.
You can add other AWS account depending files like .fog or .guignol.yml too.

Create symlinks for some config files like .aws_credentials and .fog:

ln -s ~/.aws/.aws_credentials ~/.aws_cred...

When RubyMine doesn't show you Git blames / annotate gutter not available

  • You probably haven't configured version control for your project.
  • Go to Project Settings / Version Control and set the director <Project> to Git