Search code examples
git.git-folder

How can I safely commit a .git directory


I am working on a git-related software and I have included unit tests in my code.

I have created a test git project (under a subdirectory) to be used by the tests: resources/test-git-project
This test git project is not associated to any remote, but it contains commits/tags/branches.

What is the safest way to commit the contents of resources/test-git-project in git?


Solution

  • Thanks to Thibault D. answer I found the solution I was looking for:

    I have renamed .git to gitdir and it is now commitable:

    When I want to perform updates or see the status of the test repo I do the following:

    git --git-dir=resources/test-git-project/gitdir --work-tree=resources/test-git-project anycommand
    

    Before performing the unit tests I copy the directory resources/test-git-project under /tmp and rename /tmp/test-git-project/gitdir to /tmp/test-git-project/.git, so that I don't have to mess with --git-dir option on my test code.