How to delete a folder from git history

You can follow these steps to delete a folder from git history.

#Removing folder from git history
git filter-branch --tree-filter 'rm -rf node_modules' --prune-empty HEAD
#Adding removed folder in ".gitignore" file so that we don't track it anymore
echo node_modules/ >> .gitignore
#Adding .gitignore and committing this change in repo
git add .gitignore
git commit -m 'Removing node_modules from git history'
#Now freeing up spaces from removed references
git gc
#Pushing changes to server forcefully
git push origin master --force

Clone a Git repo without history (just latest commit)

One common problem with big git repos is it takes a lot of time to clone, because in cloning git download everything beginning form the first commit. Sometimes we don’t need that much of history with code.

We can use “–depth” option in “git clone” command to specify how many commits we need. By providing an argument of “–depth 1” to the clone command, the process will copy only the latest revision of everything in the repository.

For example –

git clone --depth 1 jquery

This command only clones the HEAD of the jqueyr repository.

Note: Prior to git 1.9 we can’t use do pull or push on such repos.

multiple SSH keys for github (or bitbucket) accounts & SSH Config

If you are using multiple github account for work and home projects or you are using one github account and one bitbucket account or any other git hosting service out there with SSH you have to manage SSH keys using a config file.

Lets go through each step for setting up github and bitbucket account-

Step 1: ssh keys

Create any keypairs you’ll need. In this example I’ve named these key pairs as ‘id_rsa_github’ and ‘id_rsa_’bitbucket:

ssh-keygen -t rsa -C “"
ssh-keygen -t rsa -C “”

Step 2: ssh config

Set up multiple ssh profiles by creating/modifying ~/.ssh/config. Note the differing ‘Host’ values:

# For GitHub
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_github

# For BitBucket
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_bitbucket

Step 3: ssh-add

You may or may not have to do this. To check, list identity fingerprints by running:

$ ssh-add -l

2048 1f:1a:b8:69:cd:e3:ee:68:e1:c4:da:d8:96:7c:d0:6f (RSA)
2048 6d:65:b9:3b:ff:9c:5a:54:1c:2f:6a:f7:44:03:84:3f (RSA)

If your entries aren’t there then run:

ssh-add ~/.ssh/id_rsa_github
ssh-add ~/.ssh/id_rsa_bitbucket

Step 4: test

To test you’ve done this all correctly, I suggest the following quick check:

$ ssh -T

Hi Saurabh! You’ve successfully authenticated, but GitHub does not provide shell access.

I hope this will save someone’s hair!!

Install GitLab 5.3 on Mac OS X server 10.8.4

Below are the steps to install GitLab 5.3 on a fresh Mac OS X server 10.8.4 (server version 2.2)

1) Install a fresh mac ox x 10.8.4
2) Create user group “git” and a user “git” in this group
3) Enable remote login for “git” user
4) Install Xcode 4.6.2
5) Install command line tools in Xcode.
6) Install Home brew

$ ruby -e "$(curl -fsSL"
$ brew doctor

7) Now install some prerequisites

$ brew install icu4c # Necessary for the charlock_holmes gem install later
$ brew install git # Install git 1.8 or greater...
$ brew install redis
$ mkdir ~/Library/LaunchAgents # create launchAgents dir (it does not exist in fresh system)
$ ln -sfv /usr/local/opt/redis/homebrew.mxcl.redis.plist ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist

Make sure you have python 2.5+ (gitlab don’t support python 3.x)

$ python --version # Confirm python 2.5+
$ sudo ln -s /usr/bin/python /usr/bin/python2 #GitLab looks for python2

Some more dependices

$ sudo easy_install pip
$ sudo pip install pygments

8) Install MySql server download form here –

9) Setup database

Start MySql server from system preferences and change root password

$ /usr/local/mysql/bin/mysqladmin -u root password NEW_PASSWORD_HERE

make sure mysql is in your PATH –

$ export PATH=/usr/local/mysql/bin:$PATH

Now login in mysql

$ mysql -u root -p

#Create a new user for our gitlab setup 'gitlab'

mysql> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'PASSWORD_HERE';

#Create database
mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;

# Grant the GitLab user necessary permissions on the table.
mysql> GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';

# Quit the database session
mysql> \q

# Try connecting to the new database with the new user
sudo -u git -H mysql -u gitlab -p -D gitlabhq_production

10) Install Ruby 

$ brew install rbenv
$ brew install ruby-build

# Make sure rbenv loads in the git user's shell
$ echo 'export PATH="/usr/local/bin:$PATH"' | sudo -u git tee -a /Users/git/.profile

$ echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' | sudo -u git tee -a /Users/git/.profile

$ sudo -u git cp /Users/git/.profile /Users/git/.bashrc

# Install ruby 1.9.3 for the git user
$ sudo -u git -H -i rbenv install 1.9.3-p392
$ sudo -u git -H -i 'rbenv global 1.9.3-p392'

Install ruby 1.9.3 for your user too and set rbenv to use it. This is for installing global gems later.

$ rbenv install 1.9.3-p392
$ rbenv global 1.9.3-p392

11) Install rails 

$ sudo gem install rails

12) Install Gitlab Shell

$ cd /Users/git
$ sudo -u git git clone
$ cd gitlab-shell
$ sudo -u git git checkout v1.4.0
$ sudo -u git cp config.yml.example config.yml

Now open config.yml file and edit it
a) Change gitlab url to reflect your URL
b) Change all instances of “/home” to “/Users” (we are on mac)
c) Change redis-cli path to home-brew’s cli path – “/usr/local/bin/redis-cli”

13) Install GitLab –

Download Gitlab –

$ cd /Users/git
$ sudo -u git git clone gitlab
$ cd gitlab
$ sudo -u git git checkout 5-3-stable

Configuring GitLab

# Copy the example GitLab config
$ sudo -u git cp config/gitlab.yml.example config/gitlab.yml

Open gitlab.yml file and change “/home” to “/Users” and make sure to change “” to the fully-qualified domain name of your

# Make sure GitLab can write to the log/ and tmp/ directories
$ sudo chown -R git log/
$ sudo chown -R git tmp/
$ sudo chmod -R u+rwX  log/
$ sudo chmod -R u+rwX  tmp/

# Create directories for repositories make sure GitLab can write to them
$ sudo -u git mkdir /Users/git/repositories
$ sudo chmod -R u+rwX  /Users/git/repositories/

# Create directory for satellites
$ sudo -u git mkdir /Users/git/gitlab-satellites

# Create directories for sockets/pids and make sure GitLab can write to them
$ sudo -u git mkdir tmp/pids/
$ sudo -u git mkdir tmp/sockets/

$ sudo chmod -R u+rwX  tmp/pids/
$ sudo chmod -R u+rwX  tmp/sockets/

# Create public/uploads directory otherwise backup will fail
$ sudo -u git mkdir public/uploads
$ sudo chmod -R u+rwX  public/uploads

# Copy the example Puma config
$ sudo -u git cp config/puma.rb.example config/puma.rb

Open puma.rb file and change “/home” to “/Users”

# Configure Git global settings for git user, useful when editing via web
$ sudo -u git -H git config --global "GitLab"
$ sudo -u git -H git config --global ""

Gitlab Mysql Config.

$ sudo -u git cp config/database.yml.mysql config/database.yml

Edit production section in this database.yml file with user “gitlab” and its password

Install Gems

$ sudo gem install charlock_holmes --version ''
$ sudo -u git -H bash -l -c 'gem install bundler'
$ sudo -u git -H bash -l -c 'bundle install --deployment --without development test postgres'

Initialising Database

$ sudo -u git -H bash -l -c 'bundle exec rake gitlab:setup RAILS_ENV=production'

Got error in above –

rake aborted!
Please install the mysql2 adapter: `gem install activerecord-mysql2-adapter` (dlopen(/Users/    git/gitlab/vendor/bundle/ruby/1.9.1/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle, 9): Library     not loaded: libmysqlclient.18.dylib

So installing “activerecord-mysql2-adapter”

$ gem install activerecord-mysql2-adapter

This also did not resolved the issue so I searched again on SO and found this –

$ sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib

And run

$ sudo -u git -H bash -l -c 'bundle exec rake gitlab:setup RAILS_ENV=production'

Worked this time

Check GitLab installation

check environment configuration

sudo -u git -H bash -l -c 'bundle exec rake gitlab:env:info RAILS_ENV=production'

Do a through check. Make sure everything is green.

sudo -u git -H bash -l -c 'bundle exec rake gitlab:check RAILS_ENV=production'

If you are getting some error please fix that first.

14) Lets take it up

$ rails s -e production -p 8080

15) Now open http://localhost:8080 in your browser and login with these below details


I hope you find this above guide useful and it will save some of your time struggling missing gems, libraries, permissions etc. In next tutorial we’ll set it up on Nginx server.

GitLab 5.3 email (SMTP) setup

If you want to send gitlab emails using your gmail account (or other SMTP account), follow these steps.

1) Open /home/git/gitlab/config/environments/production.rb

(mac server users can go to usual /Users/git/gitlab…)

2) Comment this below line in code –

	config.action_mailer.delivery_method = :sendmail

3) Add this just above “end” of file

	 config.action_mailer.delivery_method = :smtp
 	 config.action_mailer.smtp_settings = {
	      :address => '',
	      :port => 467,
	      :domain => '',
	      :authentication => :plain,
	      :user_name => 'your gmail id',
	      :password => 'yourPassword',
	      :enable_starttls_auto => true

To know more on parameters see this

4) Done! You can check for setup now. Just make sure you change it every time after your gitlab updating.

Install Gitlabhq with Gitolite on Mac OS X server (Mountain Lion 10.8)

Recently I got a task of setting up a mac mini server (Mountain Lion) with gitlabhq (with gitolite). I tried for around 15 times and finally got succeed. Here are the steps which I followed to setup, hope it will help someone setting up mac server with gitlab.
Step 1 – Create a user “git”

Step 2 – Login into user “git”

Step 3 – Install xcode 4.5

Step 4 – Install command line tools in Xcode. (Xcode -> Preferences -> downloads -> install command line tools)

Step 5 – Install “rails installer” from rails (this will install many dependencies)

Step 6 – Download and Install mysql from here

Step 7 – Setup root password for mysql with this command

/usr/local/mysql/bin/mysqladmin -u root password NEW_PASSWORD_HERE

Step 8 – Install Homebrew on mac (needed to install few things)

$ ruby -e "$(curl -fsSkL"

After homebrew install run doctor –

$ brew doctor

Step 9 – Get ownership of /usr/local

$ sudo chown -R $(whoami) /usr/local

Step 10 – Install qt and icu4c with brew.

$ brew install qt
$ brew install icu4c
$ brew install redis

Step 11 – Enable ssh login in system preferences. System Preferences -> Sharing -> Enable remote login

Step 12 – Create a ssh key without a password

$ ssh-keygen -t rsa -N ''

Step 13 –Clone gitolite

$ git clone git://

Step 14 – Install gitolite

$ gitolite/install
use the following full path for gitolite:

Step 15 – Put this in .bashrc file and save in your home folder (~) –

export GIT_EXEC_PATH=/opt/local/libexec/git-core

Step 16 – Add this in .bash_profile and save in home folder (~)

$ sudo nano .bash_profile

and put this below text.

export PATH=/Users/git/gitolite/src:$PATH
export PATH=/Users/git/bin:$PATH
export PATH=/usr/local/mysql/bin:$PATH

Restart terminal

Step 17 –Setting up gitolite

Create link for .pub file

$ ln -s .ssh/

setting up gitolite with ssh key

$ gitolite setup -pk ~/

Step 18 – Making sure you can connect with ssh

$ ssh localhost

Step 19 – Confirm that you can connect to the gitolite-admin repository

$ git clone git@localhost:gitolite-admin

Step 20 – Cloning gitlabhq

$ git clone -b stable git://

Step 21 – Running “bundle” on gitlabhq

$ cd gitlabhq
$ bundle

Step 22 – Bundle complete now –

$ bundle install --without development test

Step 23 – Configuriing gitlabhq

$ cp config/database.yml.example config/database.yml
$ cp config/gitlab.yml.example config/gitlab.yml

Step 24 – Now open this “config/gitlab.yml” and change “base_path” to “Users/git/repositories”

Step 25 – Open config/database.yml and change mysql password to your root account password. for production environment.

Step 26 – Setting up gitlabhq database in production environment –

 $ bundle exec rake db:setup RAILS_ENV=production

Got this error –

rake aborted!
dlopen(/usr/local/rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.18.dylib
Referenced from: /usr/local/rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle
Reason: image not found – /usr/local/rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle

(See full trace by running task with –trace)

Got this fix on Stackoverflow –

$ sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib

Running previous command again –

$ bundle exec rake db:setup RAILS_ENV=production

 $ bundle exec rake db:setup RAILS_ENV=production

Step 27 – Run redis

$ redis-server /usr/local/etc/redis.conf

Step 28 – Run this –

$ bundle exec rake db:setup RAILS_ENV=production
$ bundle exec rake db:seed_fu RAILS_ENV=production

Step 29 – Run –

$ rails s -e production -p 8080

Step 30 – open “localhost:8080” in browser and login with –


I hope you find this guide helpful. Comments are most welcome!

.gitignore for iOS projects

You just started to use git with your iOS projects and wants to know which files you should’t track for version control? Here is a list of files you should’t track which using git –


# old skool

# Exclude the build directory

# Exclude temp nibs and swap files

# Exclude user-specific XCode 3 and 4 files
*.xcodeproj/ !*.xcodeproj/project.pbxproj

#    NB: also, whitelist the default ones, some projects need to use these

# osx noise

You just need to create a .gitignore file in your project directory and put the above content in that file.