Make Better Things

I like to make better things.

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

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.