0

I've a quite big archive of git repositories in my development path, and many of them contains branches or stashes that I may have not published around.

However I want to be sure that for no reason I end up deleting a folder and it's .git folder, while I indeed want to be able to write on it.

So wondering if there's such way to achieve this.

Basically here it is:

repo
├── .git
│   ├── config
│   ├── index
.   .
.   .
.   .

I would love to protect .git from removal when doing rm -rf repo, but ensure that I can still access in read-write mode to both the .git/config file (and friends) and be able to write a new file to .git/ itself.

Is there any way? I tried few hacks so far but none gave me such thing. Maybe using mounts could help with it more, but I would like to keep it stored all in the same place.

1
  • 1
    I am not sure you can both keep modifications rights and in the same time forbid removal.
    – Archemar
    Jul 1, 2022 at 17:02

1 Answer 1

2

You can use rm-protection

Install it by running:-

$ pip install rm-protection

The program's binary is rm-p. For convenience, add an alias:-

$ echo 'alias rm="rm-p"' >> ~/.bashrc

Since you want to protect the .git folder, run:-

$ protect .git
Question for .git: Do you really want to delete me?
Answer: Yes, I really do

You need to give it a security question and answer Then when you try to delete it:-

$ rm -rf .git/
rm-p: .git: Do you really want to delete me?
Answer: No
rm-p: Wrong answer! .git will not be removed

This program works by creating a ..git.rm-protection file with the question and answer in it.

Hope this helps ;)

3
  • 1
    This is a good suggestion, but the best thing you can do is to backup your projects (rclone, cron jobs, rsync, etc)
    – r_31415
    Jul 2, 2022 at 22:08
  • @sujay-r Well, this works, even though it's not really something that depends on the FS only, but can be acceptable.
    – Treviño
    Jul 5, 2022 at 22:50
  • @RobertSmith Indeed I'm making backups but that's not enough at times.
    – Treviño
    Jul 5, 2022 at 22:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .