当前分支代码还未提交,就切换分支报如下错
error: Your local changes to the following files would be overwritten by checkout:
Please commit your changes or stash them before you switch branches.
Aborting(请在切换分支之前提交您的更改或隐藏它们)
![](https://i-blog.csdnimg.cn/blog_migrate/8aa30417a0104386163276e8921b1cb1.jpeg)
执行命令git status查看当前工作区的文件状态
Changes to be committed:表示已经从工作区add到暂存区的文件,下一步可以进行push
![](https://i-blog.csdnimg.cn/blog_migrate/10475377259fc3ab564603d11df5f320.jpeg)
在当前分支上执行 git stash 命令,将当前分支存起来,id为 efa05be
![](https://i-blog.csdnimg.cn/blog_migrate/f388818b763a9494a935ec782a026be1.jpeg)
这时候再执行 git status 命令,显示没有东西需要提交,接着就可以在主分支master上创建并切换到新的分支
![](https://i-blog.csdnimg.cn/blog_migrate/285fce22834e8e5a29e67fd98e9c23e3.jpeg)
![](https://i-blog.csdnimg.cn/blog_migrate/433c8f7c8ae22b1649ce40bedd106be9.jpeg)