git clone을 할 때 모든 브랜치가 딸려오는 게 아니라서 (내 생각에는 default branch만 가져와지는 거 같다) 원격에 있는 기존 브랜치를 로컬 환경으로 가져와 작업해야 했다.
이 명령어를 실행하면 원격 저장소의 모든 원격 브랜치를 로컬에 가져온다.
git fetch
git fetch origin // origin 원격 저장소의 데이터를 가져옴
다음 명령어를 입력하여 원격 저장소에 어떤 브랜치들이 있는지 확인한다.
git branch -r
// git branch -a 는 모든 브랜치 조회
$ git branch -a
develop
* feat/home-foldertree
remotes/origin/HEAD -> origin/develop
remotes/origin/develop
remotes/origin/feat/ai-nonogram
remotes/origin/feat/home
remotes/origin/feat/home-checkbox
remotes/origin/feat/home-contextmenu
remotes/origin/feat/home-file
remotes/origin/feat/home-foldercontents
remotes/origin/feat/home-foldertree
remotes/origin/feat/home-upload
remotes/origin/feat/login
remotes/origin/main
원격 브랜치에는 remotes/origin 접두사가 붙은 것을 확인할 수 있다.
원격 브랜치에는 직접 작업할 수 없다. 변경 사항을 추가하기 위해서는 원격 브랜치의 복사본이 필요하다. 여기서 주의할 점이 앞에 remotes는 빼고 입력해야된다. 예를 들어 feat/login이라는 원격 브랜치를 복사하고 싶다면 다음과 같은 명령어를 실행한다.
git checkout -b feat/login origin/feat/login
feat/login이라는 새 로컬 브랜치를 생성하고,origin/feat/login의 변경 이력을 새 브랜치로 가져온다. 브랜치에서 작업을 마치고 변경 사항을 원격 저장소에 반영하려면 commit과 push를 사용한다.
git add .
git commit -m "변경 내용에 대한 설명"
git push origin [브랜치명]
이렇게 하면 로컬에서 작업한 내용이 원격 저장소의 해당 브랜치에 반영된다.