본문으로 바로가기

TIL 2022-03-22 git 원격 브랜치 가져오기, commit --amend, stash

category TIL 2022. 3. 22. 22:53
git 원격 브랜치 가져오기

 

단순 git clone으로는 main 브랜치만 가져올 수 있고 원격 브랜치를 가져오려면 다른 방법을 택해야한다.

 

먼저

git remote update

로 git remote를 갱신하여 원격 브랜치를 못찾는 일이 없도록 하고

 

git checkout -t origin/{브랜치 이름}

 

로 가져오면 된다.

 

-t는 --track으로 -b 옵션이 없으면 remote-tracking branch에서 가져오므로 원격 브랜치에서 가져오는 것!

 

-b는 new branch란 의미로 새 브랜치를 만든다는 의미다.

https://cjh5414.github.io/get-git-remote-branch/

 

Git remote branch 가져오기

Jihun's Development Blog

cjh5414.github.io

https://git-scm.com/docs/git-branch

 

Git - git-branch Documentation

If --list is given, or if there are no non-option arguments, existing branches are listed; the current branch will be highlighted in green and marked with an asterisk. Any branches checked out in linked worktrees will be highlighted in cyan and marked with

git-scm.com

 

 

git commit --amend

는 마지막 커밋에 추가적으로 추가하고 이것을 마지막 커밋 그대로 덮어씌우는 역할이다.

 

commit --amend는 마지막 커밋으로만 수정하고, 이외 과거의 커밋들을 변경하려면 rebase -i 쓰기

 

 

git stash

커밋해버리기는 껄끄럽고 현재는 필요 없는 파일이 있는 경우(작업하다가 다른 브랜치로 변경해서 작업하는 등)가 있는데, git stash로 해결가능하다

워킹 디렉토리에서 수정되었으면서 staging area에 있는 파일들을

git stash를 통해서 잠시 저장할 수 있고,

 

 

git stash list를 통해서 해당 stash id를 알 수 있고,

 

git stash apply [id]를 통해서 해당 stash로 돌아갈 수 있다.

 

stash는 스택 구조처럼 git stash pop을 통해 가장 최신 stash를 꺼낼수도 있다.

 

 

git pull 같은거 할때 작업 사항들때문에 애매한 경우 많았는데 stash 쓰면 깔끔하게 해결할 수 있을듯!

'TIL' 카테고리의 다른 글

2022-04-04 Map, WeakMap, Array.from  (0) 2022.04.04
TIL 2022-03-23 HTML 요소  (0) 2022.03.23
2022-03-19 클린코드 11~14  (0) 2022.03.19
TIL 2022-03-17 git rebase, 3-way merge  (0) 2022.03.17
TIL 2022-03-16 깃 관리 rebase, reset, force-push  (0) 2022.03.16