기존 Git Repository를 복사하여 새로운 Repository 만들기

2021. 10. 26. 16:57[개발] 지식/Git

보통 Git Repository를 복사할 때 fork를 많이 사용한다.

fork는 사실상 clone과 큰 차이가 없지만, github.com 내에서 바로 검색이 되진 않는다.

fork의 원래 의도는

bugfix를 위해 기존 repository를 복사하여, 코드 수정을 한 뒤 pull request를 날리는 것이다.

목적을 달성한 뒤 fork 프로젝트는 큰 의미가 없으므로 삭제한다.

만약 기존 Git Repository 현재 버전을 복사하여 다른 프로젝트로 활용하고자 하는 경우 git clonemirror 옵션으로 모든 이력을 갖고 온 뒤, github상에 새로 만든 repository에 push 하는 것이 맞다.

먼저 아래처럼 복사할 repository를 --mirror 옵션으로 clone한다.

--mirror 옵션을 넣으면 커밋이력까지 함께 갖고온다.

git clone --mirror {old_repository_url}

{프로젝트명}.git 디렉토리가 생성된다.

안으로 이동하자.

cd {프로젝트명}.git

remote push url을 github에 새로만든 repository로 변경한다.

git remote set-url --push origin {new_repository_url}

--mirror 옵션으로 통째로 push한다.

git push --mirror

Ref.

[Github] Repository 이동하기 clone/mirror

git clone [bare/mirror] 에 대해서 알아보기

Git Repository 복사하기

[Git] git remote url 변경

<