GIthub
[Github] 하나의 Repository에 여러 개의 프로젝트 업로드(Git Subtree)
jelliclesu
2024. 7. 9. 20:18
하나의 Repository에 여러 개의 프로젝트 업로드
Spring 공부하면서 프로젝트 하나 만들 때마다 업로드되면 너무 쓸데없이 많아지고 지저분해질 것 같아서
하나의 Repository에 여러 프로젝트를 생성하려고 이렇게 저렇게 시도해봤는데,,
자꾸 Reject 뜨면서 절대 안되고, 계속 생성하고 지우고 반복하다가 찾아보니까
subtree를 이용하는 방법이 있길래 정리해보려고 합니다!
- GitHub에 하나의 빈 Repository 생성
- 여러 프로젝트를 담을 부모 Repository 가 됨
- 부모 Repository clone
- GitHub Code 에서 주소 Copy
- Terminal에서 clone
git clone 부모Repository주소
- 부모 Repository로 이동
cd 부모Repository이름
- subtree 이용해 부모 Repository에 자식 Repository 넣기
git subtree add --prefix=폴더명 자식Repository주소 branch이름
- 폴더명은 부모 Repository에서 보여질 폴더명
- 자식Repository주소는 GitHub 주소를 뜻하기에 이미 GitHub에 자식 Repository가 존재해야 함
- ⚠️이때 부모 Repository 아무 commit이 없는 경우 오류 발생
더보기ambiguous argument 'HEAD': unknown revision or path not in the working tree
- commit 메시지 생성
-
git commit --allow-empty -n -m "커밋메시지"
- GitHub에 push
git push origin main
- ⚠️로그인 과정에서 오류 발생
더보기remote: Support for password authentication was removed on August 13, 2021. remote: Please see https://docs.github.com/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.- GitHub에서 Settings > Devloper setteings > Personal acces tokens > Tokens (classic) 클릭 후 Token 생성
- repo
- admin:repo_hook
- gist
- user
- delete_repo
- 생성된 Token 복사
- Teminal에서 다시 push 한 후, password 입력란에 복사한 Token 입력!
- GitHub에서 Settings > Devloper setteings > Personal acces tokens > Tokens (classic) 클릭 후 Token 생성
- ⚠️로그인 과정에서 오류 발생
- 부모 Repository에 자식 Repository 파일 형식으로 생성 완료
- 정상적으로 업로드가 완료되었으면, 기존 자식 Repository는 삭제해도 됨
- 이후에는 자식 Repository 넣는 부분만 해주면 됨(부모 Repository 생성 없이)
<참고 링크>
https://velog.io/@049494/하나의-리포지토리에-여러-프로젝트-올리기
https://hyeo-noo.tistory.com/184