Git | Branch
08 Jul 2021 | ETC.
Git Branch
Github는 다양한 기능들을 병렬적으로 다른 branch에서 개발하여 개발의 안정성을 보장해주는 Branch기능을 지원한다.
1. git branch
git branch
명령 프롬프트에서 Repository가 있는 경로로 이동한 후 해당 명령어를 입력하면 어떤 branch가 있는지 나온다. branch를 따로 만들지 않았으면 기본적으로 master만 있을 것이다.

branch를 추가하려면 아래 명령어를 입력하면 된다.
git branch (추가할 branch)
# ex) git branch develop

2. git checkout
git checkout으로 branch 이동이 가능하다.
git checkout (이동할 branch)
# ex) git checkout develop

branch를 이동한 상태에서 소스코드 수정, add, commit을 한 후에 log를 찍어보면 HEAD가 develop branch로 이동했고 해당 branch에서 수정된 내역이 있다는 것을 확인할 수 있다.

3. git merge
develop branch에서 변경한 사항을 master에 적용하고 싶으면 master branch로 이동한 후에 develop꺼를 master에 merge해주면 된다.
git checkout master
git merge (현재 branch에 merge하고 싶은 branch)
# ex) git merge develop

log를 찍어보면 변경사항이 develop과 mater를 향해 모두 적용된 것을 확인할 수 있다. 확인했으면 원격저장소로 push해준다.
git log
git push

4. git branch -d
branch의 쓸모가 없어졌으면 깔끔하게 지워준다. git branch의 d(delete)옵션으로 지워준다.
git branch -d (삭제할 branch)
# ex) git branch -d develop
branch 목록 찍어보면 develop은 삭제되고 master만 남아있다.
git log

Conflict
여러 branch에서 하나의 소스를 수정했는데 변경 사항이 달라 두 branch에서 가지고 있는 소스의 상태가 같지 않을 경우, merge(merge는 일반적으로 master branch에서 함)를 할 때 충돌이 생길 수 있다. 이때 아래와 같은 conflict message가 뜬다.

충돌이 일어난 파일을 열어보면 아래 그림처럼 충돌 부분이 나타나있다.

충돌부분을 확인하고 직접 고쳐주고 add, commit하면 해결된다. merge명령으로 확인해보면 merge가 이미 되었다고 나온다.

이제 push하면 완전 끝 마무리.
Git branching model은 https://nvie.com/posts/a-successful-git-branching-model여기 설명 잘 되어 있음
Git Branch
Github는 다양한 기능들을 병렬적으로 다른 branch에서 개발하여 개발의 안정성을 보장해주는 Branch기능을 지원한다.
1. git branch
git branch
명령 프롬프트에서 Repository가 있는 경로로 이동한 후 해당 명령어를 입력하면 어떤 branch가 있는지 나온다. branch를 따로 만들지 않았으면 기본적으로 master만 있을 것이다.

branch를 추가하려면 아래 명령어를 입력하면 된다.
git branch (추가할 branch)
# ex) git branch develop

2. git checkout
git checkout으로 branch 이동이 가능하다.
git checkout (이동할 branch)
# ex) git checkout develop

branch를 이동한 상태에서 소스코드 수정, add, commit을 한 후에 log를 찍어보면 HEAD가 develop branch로 이동했고 해당 branch에서 수정된 내역이 있다는 것을 확인할 수 있다.

3. git merge
develop branch에서 변경한 사항을 master에 적용하고 싶으면 master branch로 이동한 후에 develop꺼를 master에 merge해주면 된다.
git checkout master
git merge (현재 branch에 merge하고 싶은 branch)
# ex) git merge develop

log를 찍어보면 변경사항이 develop과 mater를 향해 모두 적용된 것을 확인할 수 있다. 확인했으면 원격저장소로 push해준다.
git log
git push

4. git branch -d
branch의 쓸모가 없어졌으면 깔끔하게 지워준다. git branch의 d(delete)옵션으로 지워준다.
git branch -d (삭제할 branch)
# ex) git branch -d develop
branch 목록 찍어보면 develop은 삭제되고 master만 남아있다.
git log

Conflict
여러 branch에서 하나의 소스를 수정했는데 변경 사항이 달라 두 branch에서 가지고 있는 소스의 상태가 같지 않을 경우, merge(merge는 일반적으로 master branch에서 함)를 할 때 충돌이 생길 수 있다. 이때 아래와 같은 conflict message가 뜬다.

충돌이 일어난 파일을 열어보면 아래 그림처럼 충돌 부분이 나타나있다.

충돌부분을 확인하고 직접 고쳐주고 add, commit하면 해결된다. merge명령으로 확인해보면 merge가 이미 되었다고 나온다.

이제 push하면 완전 끝 마무리.
Git branching model은 https://nvie.com/posts/a-successful-git-branching-model여기 설명 잘 되어 있음