현재 프론트를 담당하는 팀원이 잘못된 코드를 올려 파일을 제거해야 될 상황이 되었다.
깃허브의 upstream은 다른 개발자의 원격 저장소에 있는 변경사항을 가져오는 기능이다. 이를 통해 협업하고 있는 프로젝트의 최신 업데이트를 받아올 수 있다.
# (최초 한 번만) 팀 리포지토리를 'upstream'으로 추가
# git remote add upstream [팀_리포지토리_URL]
# (최초 한 번만) upstream으로의 직접 푸시 방지 설정 (권장)
# git remote set-url --push upstream no_push
# --- 여기서부터는 작업할 때마다 반복 ---
# 1. 로컬 리포지토리
git checkout backend
# 2. upstream(팀 리포지토리)의 최신 main 브랜치 내용으로 로컬 main 업데이트
git pull upstream main
# 3. 새로운 작업 브랜치 생성 및 이동 <선택사항이지만 하면 좋음>
git checkout -b cleanup-project-structure
# 4. 파일 제거 작업 실행 (예시)
git rm path/to/your/file/to/remove.ext
# 5. 변경사항 스테이징
git add path/to/your/file/to/remove.ext
# 또는 관련된 모든 변경사항을 추가하려면: git add .
# 6. 변경사항 커밋
git commit -m "Remove unnecessary file: file/to/remove.ext"
# 7. 개인 리포지토리(origin)에 작업 브랜치 푸시
git push origin cleanup-project-structure
# 이후 PR 요청
먼저 팀 리포지토리 브랜치 이름이 오타가 있어서 브랜치 이름을 수정을 해준다.
원격 저장소에서 잘못된 이름의 브랜치 삭제
# (최초 한 번만) 팀 리포지토리를 'upstream'으로 추가
# git remote add upstream [팀_리포지토리_URL]
# upstream으로의 직접 푸시 방지 설정 (잠시 해제)
# git remote set-url --push upstream no_push
git remote set-url --push upstream [팀_리포지토리_URL]
# 브랜치 이름 변경
git branch -m develop
# 브랜치 이동
git checkout develop
# 원격 저장소 최신 정보 가져오기
git fetch upstream --prune
# 새 이름(develop)으로 브랜치 푸시
git push upstream develop
# 기존 이름(devleop)의 원격 브랜치 삭제
git push upstream --delete devleop
# pstream으로의 직접 푸시 방지 설정 (권장)
# git remote set-url --push upstream no_push
팀원이 설정해야 할 코드
# upstream 리모트의 최신 정보를 가져오고, 원격에서 삭제된 devleop 브랜치 정보를 로컬에서도 정리
git fetch upstream --prune
# 로컬 devleop 브랜치 처리
git checkout devleop
git branch -m develop
# 이름 변경된 로컬 develop 브랜치가 upstream/develop을 추적하도록 설정
git branch -u upstream/develop
# 또는 git branch --set-upstream-to=upstream/develop develop
# 최신 원격 develop 내용과 동기화
git pull
# 상태 확인
git status
git branch -vv