본문 바로가기

개발/Git & Github

[Git] Stash를 적용한 브랜치 만들기

반응형
$ git stash branch [branch name]

위와 같은 명령어가 있다.

대개는 작업할 때, stash를 한 이후에, stash apply 혹은 stash pop 을 하는 식으로 작업 할 텐데, 새로운 브랜치를 생성하고 해당 브랜치에서 작업을 해야한다면 아래와 같은 step을 거치게 된다.

(thkwon) ➜  coding_kata git:(master) ✗ git stash                   
Saved working directory and index state WIP on master: 44a211e 210104
(thkwon) ➜  coding_kata git:(master) git checkout -b test-branch               
Switched to a new branch 'test-branch'
(thkwon) ➜  coding_kata git:(test-branch) git stash pop              
On branch test-branch
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   code_wars/python/8kyu/210104_generate_range_of_integers.py

no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (480231a8778dced55055bae2a129119b8a43b602)

 

stash branch 는 위 명령어를 한번에 해주는 명령어 이다.

(thkwon) ➜  coding_kata git:(master) ✗ git stash                   
Saved working directory and index state WIP on master: 44a211e 210104
(thkwon) ➜  coding_kata git:(master) git stash branch test-branch
Switched to a new branch 'test-branch'
On branch test-branch
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   code_wars/python/8kyu/210104_generate_range_of_integers.py

no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (ea4a08f510fbc471190135dc7ad9a514a3605f37)

 

stash를 한 내용에 대해서 따로 격리된 환경에서의 테스트가 필요할 때, 위 명령어를 유용히 사용할 수 있다.

반응형