git branch 사용
HappyCoding/git

git branch 사용

git branch new-branch # new-branch라는 이름의 브랜치가 만들어진다.

# new branch는 새롭게 만들어진게 아니라 new branch라는 포인터가 3345766을 가리키고 있는 것임.

git switch new-branch # 새로만든 'new-branch' 로 이동

git switch master # master로 다시 이동

 

git switch -C new-branch2 # new-branch2를 만들고 그 곳으로 이동

 

git switch checkout ~~~~ #checkout은 정말 유용하게 해쉬코드(~~~~~)를 작성하면 그곳(~~~~)으로 이동 (HEAD가 그곳을 보고 있다.

ex) git checkout bd7bd28

 

git checkout fix #HEAD가 다시 fix로 이동되어있는 것 확인 가능

 

git checkout -b testing #새로운브랜치 testing만들어서 이동함.

 

git switch master #다시master branch로 감.

 

git branch #branch의 정보를 확인하기.

 

git branch -v # 간단하게 최신commit들도 확인가능.

 

git branch --merged  #현재 branch에 merge된 branch 볼 수 있다.

 

feature-a 라는 branch는 브랜치 만들어서 merge해놓음

나머지 밑에 두 개는 생성만 하고 나머지 파생이 없으므로 밑에 표기됨.

 

git branch --no-merged   # master branch에서 merge가 되지않은(=master branch에서 파생된 다른 변경사항, 다른 commit이 있는 경우) 브랜치만 보여준다.

 

 

fix 라는 branch에 하나의 commit이 있는 것을 볼 수 있다..

 

git merge fix    #간단하게 fix branch를 merge하고 hist를 다시 보면 merge된 것 확인 가능

 

git branch  

 

git branch -d new-branch2 # new-branch2를 없애고 싶다.

 

 

git push origin --delete new-branch2  #origin 원격에도 new-branch2없앤 거 올리기.

# 당연히 원격의 repository가 없기 때문에 에러가 발생함.

 

 

git branch --move fix fix-welcome     # fix를 의미있는 이름으로 변경하고 싶음.

git push --set-upstream origin fix-welcome # 이것도 원격에 업뎃 

 

 

 

git switch -C test#master branch에서 test branch를 만들고, test브랜치로 이동해보기.

git checkout -b test #이렇게도 가능

 

echo test > test.txt   #echo라는 linux 명령어 이용해서 test file만들기

 

git add . 

git commit -m "test"

 

 

git checkout master #master branch로 이동해보기..

 

git log master..test  #master 와 test branch사이의 log(commit)만 확인 해보고 싶다.

 

git hist master..test  # 위와 동일하게.

 

 

git diff master..test  #달라진 code 보고 싶다면?

'HappyCoding > git' 카테고리의 다른 글

git merge option : no-ff (no fast-forward)  (0) 2021.05.02
fast-forward merges  (0) 2021.05.02
git tag  (0) 2021.05.01
git 명령어  (0) 2021.05.01
TIL git log 예쁘게 만들기.  (0) 2021.05.01