git snippets

Fix for empty ident error using older git

Tagged git  Languages bash

In this snippet Christian explains how to fix the empty ident error using a bleeding edge git. In older git versions this must be done manually. So if you get this error...

*** Environment problem:
*** Your name cannot be determined from your system services (gecos).
*** You would need to set GIT_AUTHOR_NAME and GIT_COMMITTER_NAME
*** environment variables; otherwise you won't be able to perform
*** certain operations because of "empty ident" errors.
*** Alternatively, you can use configuration variable.

fatal: empty ident  <> not allowed

... then add the following parameters to your /.bashrc\ file\ and\ source\ it\ with\ ./.bashrc (or relogin, alternatively):

export GIT_AUTHOR_NAME="Marko Haapala"
export GIT_COMMITTER_NAME="Marko Haapala"

Installing git without getting screwed over when it's time to uninstall, upgrade or install package maintainer's version

Tagged git, xstow, stow  Languages bash

Although Git is one of the better source code managers it has a major drawback if you need to install it from the sources - it's makefile doesn't have an uninstall target as defined in the GNU coding standards. Therefore you might find your system screwed over when you want to uninstall or upgrade after installing from sources. This is a workaround that is sufficient enough to make me break my rule of not installing software outside of package management.

Also see the snippet for an alias for the make command first.


sudo apt-get install asciidoc xsltproc xmlto xstow bzip2 build-essential zlib1g-dev tcl8.4


cd /tmp
tar xjvf git-
sudo mv git- /usr/src
sudo ln -s /usr/src/git- /usr/src/git
cd /usr/src/git
./configure --prefix=/usr/local/stow/git
make all doc
sudo make install install-doc
cd /usr/local/stow
cat << EOF > /tmp/xstow.ini
# this is the xtow configuration file
# see xstow.ini(5) for details

# list of links that will be handled as normal directories
keep-targets = true      # add targets of the links to the keep-dirs section
link = /usr/local/tmp
link = /usr/local/var
link = /usr/local/man
link = /usr/local/share
link = /usr/local/share/man
link = /usr/local/doc
link = /usr/local/info
add-if-target = /*       # automatic add all absolute links

# directories that never should be removed
dir = /usr/local/bin
dir = /usr/local/sbin
dir = /usr/local/lib
dir = /usr/local/include
dir = /usr/local/share

ignore = *~      # emacs
ignore = core    # core file
ignore = core.*  # new style
ignore = CVS     # CVS directories
ignore-regex = [0]+README.*

# make other stow dirs public
dir = /usr/local/local/stow
dir = /usr/local/local/stow2

module = ALL
level  = 0

in-home = yes
in-stow-dir = yes
in-other-stow-dirs = yes
file = /etc/xstow.ini
file = /usr/local/local/etc/xstow.ini

absolute-paths = false
sudo mv -i /tmp/xstow.ini .
sudo xstow git


cd /usr/local/xstow
xstow -D git
sudo rm -rf /usr/local/stow/git

Kind of makes one appreciate the work done by package maintainers, doesn't it?

"updating paths is incompatible with switching branches/forcing" error when using git branches with Vlad

Tagged vlad, git, branch, deploy, revisions, tags  Languages 

I ended up writing this snippet after I found out that deploying a git branch with vlad wasn't as easy as it should've been...

I assumed the Vlad documentation was right, so I put the branch name in the revision variable (located in config/deploy.rb):

set :revision,              'branch_name'

But then I got this error when executing rake vlad:deploy:

git checkout: updating paths is incompatible with switching branches/forcing
Did you intend to checkout 'branch_name' which can not be resolved as commit?

I managed to solve the problem by using the SHA1 hash of the branch instead of the branch name, but that only worked for the current revision:

set :revision,              'd34360870be6536992e6d45bb0aa72eca31e14443'

So after some googling I found this post at, which made my day because it has the following examples of how to deploy tags and branches with git and Vlad:

# Deploy the latest code, this the default
set :revision, "HEAD" 

# Deploy branch "origin/branch_name"
set :revision, "origin/branch_name"
# Deploy tag "1.0"
set :revision, "1.0"

Note that you have to push the branch to the remote server before running rake vlad:deploy:

git push origin branch_name

Using thin with Vlad the Deployer

Tagged vlad, thin, git  Languages 

To get Vlad 1.2.0 to work with Thin I did the following.

First change the line where Vlad is included to this:

Vlad.load :scm => :git, :app => :thin

Now run vlad:setup:

$ rake vlad:setup
(in /Users/christian/Documents/Projects/
Unable to load Vlad no such file to load -- vlad/thin
rake aborted!
Please specify the server domain via the :domain variable

(See full trace by running task with --trace)

The fix for this error:

Unable to load Vlad no such file to load -- vlad/thin

Is to run the following command:

curl -o /usr/local/lib/ruby/gems/1.8/gems/vlad-1.2.0/lib/vlad/thin.rb

How to fix "fatal: 'gitosis-admin.git': unable to chdir or not a git archive"

Tagged git, fatal, gitosis, install, setup  Languages bash

Are the SSH keys valid?

When, not if, you get this error you most probably have the wrong keys listed in /home/git/.ssh/authorized_keys:

$ git  clone 
Initialized empty Git repository in /Users/christian/Documents/Projects/gitosis-admin/.git/
fatal: 'gitosis-admin.git': unable to chdir or not a git archive
fatal: The remote end hung up unexpectedly

Try removing the keys in authorized_keys one by one, and verify that the names of the users match the ones in .gitosis.conf

Try using the full path to the repository

$ git clone

Check if the repository exists

$ cd /home/git/repositories/xxx.git
$ git clone /home/git/repositories/xxx.git

What does SSH say?

ssh -v

Use Google

Simple script for adding existing project to git/gitosis

Tagged git, gitosis, script  Languages bash

touch tmp/.gitignore log/.gitignore vendor/.gitignore
find . -type d -empty | grep -v "vendor" | grep -v ".git" | grep -v "tmp" | xargs -I xxx touch xxx/.gitignore

cat <<EOF >>.gitignore

git init
git add .
git commit -m "initial commit" 
git remote add origin $GIT_USER@$SERVER:$APP.git
git push origin master

How to move a local Git repository to a shared server

Tagged git  Languages apacheconf

Short version:

# On server
git init --bare /var/www/xyz/frontend.git

# On local
git remote add server
git push server master

Longer version:

# On local computer
git clone --bare . xxx.git
tar cvf xxx.tar xxx.git
scp xxx.tar

# On remote server
cd /var/git/repositories
tar xvf /tmp/xxx.tar

# On local computer
git remote add origin ssh://
git push origin master

Git: "fatal: protocol error: bad line length character:"

Tagged git, bash  Languages bash

Git might give you this fine error

fatal: protocol error: bad line length character:

Looks like git didn't receive the response it expected from your server.

Possible causes: * Did you put some echo commands in e.g. ~/.bashrc on the remote server?

Git Configuration

Tagged git, configuration  Languages bash

Makes git output look better:

git config format.pretty oneline
git config color.ui true