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?

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

Extract Git directory to new repository

Tagged git, repository  Languages bash

This will extract lib/module_b sub directory to a new Git repository while preserving Git history for that sub directory:

git clone module-b
cd module-b
git remote rm origin
git filter-branch --subdirectory-filter lib/module_b -- --all


How to fix "Permission denied (publickey)." Ansible and "git clone" issue

Tagged ansible, git  Languages bash

If you have a "git clone" command like this in Ansible:

- name: Update code
  git: >
    repo={{ git_url }}
    dest={{ this_release_path }}
    version={{ git_version }}
  register: git

And the playbook is set to use sudo for all commands.

And you get this error:

stderr: Cloning into 'jeb-bush'...
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

FATAL: all hosts have already failed -- aborting

It could be that you need to add "sudo: no" to the task.

- name: Update code
  sudo: no
  git: >
    repo={{ git_url }}
    dest={{ this_release_path }}
    version={{ git_version }}
  register: git