gitgit-init

git init --separate-git-dir overwrites the existing .git folder


I have a repo:

mkdir test
cd test
git init
touch hi.txt
git add .
git commit -m 'first test add'
git status

Wherein I'd like to add a separate git repo to manage different work:

git init --separate-git-dir .git2

Running this command, however overwrites .git with file that stores a symlink.

I don't want this to happen :(

I'd like to have the original .git repo/folder and .git2 live in harmony...

So that I can run commands like:

git --git-dir=.git2 add new_file.txt

Thanks!


Solution

  • Solved the problem with:

    git --work-tree=. --git-dir=git2 init
    

    Instead of using the --separate-git-dir flag

    Each subsequent command now requires:

    git --work-tree=. --git-dir=git2 status
    git --work-tree=. --git-dir=git2 add .
    git --work-tree=. --git-dir=git2 commit -m 'yay!'
    

    Janky. But it's exactly what I needed...