Checkout another branch when there are uncommitted changes on the current branch

前端 未结 5 2037
北恋
北恋 2020-11-21 06:10

Most of the time when I try to checkout another existing branch, Git doesn\'t allow me if I have some uncommitted changes on the current branch. So I\'ll have to commit or s

5条回答
  •  情深已故
    2020-11-21 06:47

    You have two choices: stash your changes:

    git stash
    

    then later to get them back:

    git stash apply
    

    or put your changes on a branch so you can get the remote branch and then merge your changes onto it. That's one of the greatest things about git: you can make a branch, commit to it, then fetch other changes on to the branch you were on.

    You say it doesn't make any sense, but you are only doing it so you can merge them at will after doing the pull. Obviously your other choice is to commit on your copy of the branch and then do the pull. The presumption is you either don't want to do that (in which case I am puzzled that you don't want a branch) or you are afraid of conflicts.

提交回复
热议问题