Git 디렉토리에 화살표 폴더 클릭 불가, 서브모듈 문제 해결

➜  포트폴리오 git:(main) ✗ git add .
warning: adding embedded git repository: terraform/learn-terraform-advanced-deployments
hint: You've added another git repository inside your current repository.
hint: Clones of the outer repository will not contain the contents of
hint: the embedded repository and will not know how to obtain it.
hint: If you meant to add a submodule, use:
hint:
hint:   git submodule add <url> terraform/learn-terraform-advanced-deployments
hint:
hint: If you added this path by mistake, you can remove it from the
hint: index with:
hint:
hint:   git rm --cached terraform/learn-terraform-advanced-deployments
hint:
hint: See "git help submodule" for more information.
warning: adding embedded git repository: terraform/learn-terraform-aws-asg
warning: adding embedded git repository: terraform/learn-terraform-modules-create
warning: adding embedded git repository: terraform/learn-terraform-modules-use
warning: adding embedded git repository: terraform/learn-terraform-provision-eks-cluster

문제 원인

Git을 사용하다 보면 최상위 디렉토리에 다른 폴더를 추가하려고 할 때, 다음과 같은 경고 메시지가 나타날 수 있습니다 위 경고 메시지는 terraform/learn-terraform-aws-asg 등 이로 인해 최상위 디렉토리에서 이들을 추가하려고 할 때 문제가 발생하게 됩니다.

해결 방법

이 문제를 해결하려면 다음과 같은 절차를 따르세요:

잘못 추가된 서브모듈 제거
git rm --cached 명령어를 사용하여 잘못 추가된 서브모듈을 제거합니다.

git rm --cached terraform/learn-terraform-advanced-deployments
git rm --cached terraform/learn-terraform-aws-asg
git rm --cached terraform/learn-terraform-modules-create
git rm --cached terraform/learn-terraform-modules-use
git rm --cached terraform/learn-terraform-provision-eks-cluster

안지워지면 -rf 플래그 써보세요.

변경 사항 커밋
변경 사항을 반영하여 커밋합니다.

git add .
git commit -m "잘못 추가된 서브모듈 제거"

스크린샷

문제 원인

하위 디렉토리 내에 .git 폴더가 존재할 때 발생합니다. 이는 해당 디렉토리가 독립적인 Git 리포지토리로 취급된다는 의미입니다.

해결 방법

로컬 .git 폴더 삭제
하위 디렉토리 내 .git 폴더를 삭제하여 해당 디렉토리가 독립적인 리포지토리로 인식되지 않도록 합니다.

rm -rf terraform/learn-terraform-advanced-deployments/.git
rm -rf terraform/learn-terraform-aws-asg/.git
rm -rf terraform/learn-terraform-modules-create/.git
rm -rf terraform/learn-terraform-modules-use/.git
rm -rf terraform/learn-terraform-provision-eks-cluster/.git

이 과정들을 거치면 깃허브 상에서 화살표 폴더 문제와 클릭 불가 문제를 해결할 수 있습니다.

결론

Git 리포지토리를 관리할 때, 서브모듈이 의도치 않게 포함되면 여러 문제가 발생할 수 있습니다. 이러한 상황에서 서브모듈을 적절히 제거하고 .git 폴더를 삭제함으로써 문제를 해결할 수 있습니다.


출처