Git repository 병합하며 잔디 유지하기

shleecloud·2022년 6월 1일
0
post-thumbnail

들어가며

부트캠프를 하면서 fork 받은 Repository가 굉장히 많았다. 무작정 삭제하자니 추억(a.k.a. 잔디)가 아까웠다. 이전에 스쳐지나가듯 잔디를 유지하면서 통합하는 방법이 있다고 들었다. Lerna monorepo에 대해서 공부하던 차에 통합 작업을 계획했다. 시간이 몇 시간 걸렸지만 깔끔해진 목록을 보니 속이 시원하다.

작업 절차

  1. 통합 repository를 생성한다.
  2. 로컬 환경에 통합 repo를 git clone
  3. 타겟 repository를 원격 저장소로 할당한다. git remote add
  4. 이전 commit 기록을 불러온다. git fetch
  5. 서로 관련없는 프로젝트를 병합하는 옵션을 포함해서 병합한다. git merge --allow-unrelated-histories
  6. 충돌을 해결하고 커밋한다. git commit -a
  7. 3번으로 돌아가서 새로운 레포를 병합한다.

명령어

git remote add im-target https://github.com/shleecloud/im-target.git
git fetch im-target
git merge --allow-unrelated-histories im-target/master
git commit -a

간편화 스크립트

엉성하지만 유용하게 사용했다. tgt 변수에 git 주소를 할당하면 명령어를 만들어준다. 완전 자동화도 만들고 싶었지만 .gitignore 파일이 자꾸 충돌하는 바람에 의욕이 떨어져 반자동화로 만족했다.

const tgt = 'https://github.com/myid/im-sprint-target.git'

const tgtArr = tgt.split('/')
const tgtName = tgtArr[tgtArr.length - 1].slice(0,-4)

console.log(`

mkdir ${tgtName}
git remote add ${tgtName} ${tgt}
git fetch ${tgtName}
git merge --allow-unrelated-histories ${tgtName}/master

`)

참조 URL

https://velog.io/@soyeon/Git-GitHub-%EC%97%AC%EB%9F%AC-%EA%B0%9C%EC%9D%98-Repository-%EB%B3%91%ED%95%A9-commit-history-%EC%9C%A0%EC%A7%80
https://backlog.com/git-tutorial/kr/stepup/stepup3_2.html

profile
블로그 옮겼습니다. https://shlee.cloud

0개의 댓글