소소한 개발 공부
merge할 때 git command 정리 본문
merge 할 때 pull request를 해서 관리자가 merge를 하게 할 수 있는데 그 방법 말고 직접적으로 저장소를 merge 하는 방법이다.
이 포스트에서는
나는 개인 브랜치(A)에 있고, 원격 main에 올라와 있는 commit을 내려받아 내 status과 merge 하고 다시 main에 올려놓는 작업을 한다.
* 나는 git merge 는 vscode GUI 를 사용하고, checkout 등 분기 관리는 git Bash로 하기 때문에 명령어들 위주로 정리한다.
(현재 위치 - A)
git checkout main
(현재 위치 - main)
git pull origin main
git checkout -b mergeTest
(현재 위치 - mergeTest)
git merge A
... 병합 진행 ... (vscode GUI로 해결)
git commit -m "merge complete"
git ckeckout A
(현재 위치 - A)
git merge mergeTest
git push origin A
git checkout main
(현재 위치 - main)
git merge A
git push origin main
=> A의 상태를 main에 merge 해서 원격 저장소(origin/main)에 업로드 완료!
git status 를 확인 안하고 명령어를 작성했을 때 에러가 날 수 있다. 당황하지 말자! git은 친절하게 왜 안되는지 알려준다!
error: Your local changes to the following files would be overwritten by checkout:
파일이름
Please commit your changes or stash them before you switch branches.
Aborting
=> working tree에 commit 되지 않은 변경사항이 있는데 왜 브랜치를 변경하냐는 말이다.
working tree에 되돌려도 되는 파일만 있다면 discard 한다.
git checkout -- .
혹은 커밋을 남기고 싶다면 staging 후 커밋한다.
git add .
git commit -m "commit this"
'개발 > Git' 카테고리의 다른 글
Mac 에 git 설치하기 (0) | 2021.06.27 |
---|---|
git 폴더의 remote를 다른 주소의 remote로 수정하기 (0) | 2021.05.26 |
fatal: couldn't find remote ref master (0) | 2021.04.12 |
Git Clone으로 저장소에서 파일 내려받고 다른 저장소에 연결하기 (0) | 2020.11.18 |