3

I have a bash script, called cgit, that acts as git for one specific git repo (located at /.git):

#!/bin/bash
cd /;
sudo git $@ > /dev/stdout

I use it to keep track of imporant system files:

cgit add /etc/rc.conf

The trouble is when I try to add content relative to the directory I'm in, for example:

cd /home/user
cgit add .ssh/config

cgit would try and add /.ssh/config to the /.git repo.

Any suggestions or work-arounds?

1
  • the title is wrong, but i have no idea what else to title this question
    – Stefan
    Sep 9, 2010 at 13:36

2 Answers 2

3

I'd update your cgit script to use --git-dir. From the man pages:

   --git-dir=<path>
       Set the path to the repository. This can also be controlled by
       setting the GIT_DIR environment variable. It can be an absolute
       path or relative path to current working directory.

So it would become:

#!/bin/bash
sudo git --git-dir=/.git $@ > /dev/stdout

FTR, I haven't tried it.

1
  • works like a charm
    – Stefan
    Sep 9, 2010 at 17:47
2

Much better to use etckeeper instead of your own home-grown solution. There are number of gotchas that etckeeper addresses nicely. It's a package in several Linux distros, and is also easy to build from source.

A really nice feature on Debian-based systems is that it ties in with apt to automatically commit before and after installing or updating packages. This helps distinguish changes you made yourself from ones made by package updates. It also (optionally) does a daily autocommit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.