git and dreamhost : refusing to update checked out branch: refs/heads/master

Problem
After dreamhost decided to move my account that hosted the git repository to a new server, first time I’ve tried to push some changes to the git repository I was faced with the followng error:

Counting objects: 13, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (7/7), done.
Writing objects: 100% (7/7), 699 bytes, done.
Total 7 (delta 6), reused 0 (delta 0)
error: refusing to update checked out branch: refs/heads/master
error: By default, updating the current branch in a non-bare repository
error: is denied, because it will make the index and work tree inconsistent
error: with what you pushed, and will require 'git reset --hard' to match
error: the work tree to HEAD.
error:
error: You can set 'receive.denyCurrentBranch' configuration variable to
error: 'ignore' or 'warn' in the remote repository to allow pushing into
error: its current branch; however, this is not recommended unless you
error: arranged to update its work tree to match what you pushed in some
error: other way.
error:
error: To squelch this message and still keep the default behaviour, set
error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To ssh://dh_user@dh_domain/home/repository_path/projects/project.git

Solution
After searching and finding out various solutions to solve the problem, none of which was specific to a server move, I’ve tried the following:

  • Followed the steps here to set up a new repository project_asm.git
  • went to local project changed the config file to add the new remote repository
  • issued git push new_remote master
  • make a code change and then git push

And everything should work as normal again.

Deploying a Rails project in a server that hosts the git repository

Problem
You want to deploy your project in a server (dreamhost), that also hosts your git repository. When you try to do that by only setting the set_repository, you get errors like ‘permission denied, please try again’, even though if you try to checkout the git repository on your server works.

Solution
Set your :repository as a file in your host as in:
set :repository, "file:///home/username/git_on_server/projects/repo_name.git"

Then also set up your local_repository, as in:
set :local_repository, "user_name@server_domain_name:/home/username/git_on_server/projects/repo_name.git"

Getting your Github git project to dreamhost

Problem
You already have a project in github, but you want to move it to a different host (ie dreamhost)

Solution
Following the post here that describes how to setup a new git repository in dreamhost, the only difference after the initial setup :

ssh username@dreamhost_domain.com

mkdir -p ~/git/yourproject.git

cd ~/git/yourproject.git

git --bare init

is to edit your project’s .git/config file:
vi local_host/your_project/.git/config

and change the :
url = git@github.com:user_name/project_name.git

to the following:
ssh://dreamhost_username@dreamhost_domain/~/git/yourproject.git

Lastly you have to push for the first time to the server:
git push origin master

Optionally if you would like to check and/or checkout to a different pc you can use:
git clone ssh://dreamhost_username@dreamhost_domain/~/git/yourproject.git

git: fatal error: `chdir’ failed: permission denied.

Problem
Trying to use the heroku gem to clone a project and do local modifications I got the following error:

git: fatal error: `chdir' failed: permission denied.

Solution
It turns out that in Mandriva, when using:

sudo urpmi git

what gets installed is the ‘GNU Interactive Tools’ that has nothing to do with the git version control system.
So make sure you first uninstall the git installed:

sudo rpm -e git

and then install the Git – Fast version control system, by doing:

sudo urpmi git-core

You should then be able to clone a heroku application:

heroku clone myapp