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 user.name configuration variable.

fatal: empty ident  <.....@......com> 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.

Prequisities

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

Installation

cd /tmp
wget http://kernel.org/pub/software/scm/git/git-1.5.5.1.tar.bz2
tar xjvf git-1.5.5.1.tar.bz2
sudo mv git-1.5.5.1 /usr/src
sudo ln -s /usr/src/git-1.5.5.1 /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
[traverse-links] 
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
[keep-dirs]
dir = /usr/local/bin
dir = /usr/local/sbin
dir = /usr/local/lib
dir = /usr/local/include
dir = /usr/local/share

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

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

[debug]
module = ALL
level  = 0

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

[links]
absolute-paths = false
EOF
sudo mv -i /tmp/xstow.ini .
sudo xstow git

Uninstallation

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 scie.nti.st, 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/nyhetsanka.fi)
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 http://github.com/dpiddy/vlad/raw/master/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 git@xxx.com:gitosis-admin.git 
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

http://scie.nti.st/2007/11/14/hosting-git-repositories-the-easy-and-secure-way

Try using the full path to the repository

$ git clone git@xxx.com::/home/git/repositories/xxx.git

Check if the repository exists

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

What does SSH say?

ssh -v git@xxx.com

Use Google

http://stackoverflow.com/questions/1264262/connecting-to-gitosis-server-through-an-ssh-tunnel http://stackoverflow.com/questions/733057/can-git-work-via-ssh-port-forwarding

Simple script for adding existing project to git/gitosis

Tagged git, gitosis, script  Languages bash
GIT_USER=git
SERVER=xxx.com
APP=xxx

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
.DS_Store
log/*.log
tmp/**/*
config/database.yml
db/*.sqlite3
*.swp
Capfile
EOF

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 xxx@xyz.com:/var/git/frontend.git
git push server master

Longer version:

# On local computer
git clone --bare . xxx.git
tar cvf xxx.tar xxx.git
scp xxx.tar xxx.com://tmp

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

# On local computer
git remote add origin ssh://john@xxx.com/var/git/repositories/xxx.git
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