호랑이 개발일기

git checkout시 발생하는 오류 error: Your local changes to the following files would be 본문

Git & Github

git checkout시 발생하는 오류 error: Your local changes to the following files would be

박개발 2023. 6. 17. 20:58
728x90

git checkout 시 발생하는 에러

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

 

다른 브랜치로 이동하기 전 작업하고 있던 브랜치에서 변경사항이 있는데, 제대로 커밋(저장)하지 않아 발생하는 오류이다.

해결방법

사실 오류 메시지에 해결 방법이 이미 나와있다.
Please commit your changes or stash them before you switch branches.
해당 브랜치를 커밋(commit)하거나 임시저장(stash)하면 된다.

1. commit
말 그대로 작업하고 있던 파일을 commit 하면 된다.

2. stash
불필요한 커밋이 싫다면 파일을 잠시 임시저장하고 다른 브랜치로 이동할 수도 있다.

임시저장할 브랜치에서 git stash 명령어 실행

git stash


브랜치 이동 후 작업

git checkout <이동할 브랜치>


작업이 끝났다면 다시 임시저장한 브랜치로 돌아와서 임시저장한 파일 불러오기

git checkout <원래 작업하던 브랜치>
git stash pop
728x90
Comments