Skip to main content

Posts

Showing posts from 2019

GIT :: Switch branch without discarding local changes

Sometimes you modified files in a branch and you need to switch current branch into different branch without committing them. You need to stash them first. $ git checkout develop error: Your local changes to the following files would be overwritten ... Run git stash save, or just plain git stash which is short for save $ git stash save Those are safely stored in the repository. After switch branch and you want will apply them. $ git checkout develop Switched to branch 'develop' $ git stash apply If it is successful you need to delete references to the commits.  $ git stash drop    But if you apply option does a merge stashed changes. $ git stash apply   There may be merge conflicts. All went successfully you can drop stash $ git stash drop git stash pop is short-hand for git stash apply && git stash drop

GIT Error: The following untracked working tree files would be overwritten by merge:

Recently I renamed following file names(changed only captal to simple) and added to branch(abc) and commited them. I pushed the branch as well.  app/SocialMedia/EmailShare.php --> app/SocialMedia/Emailshare.php         app/SocialMedia/EmailShareFactory.php ---> app/SocialMedia/EmailshareFactory.php After that I tried to checkout a different branch(beta). Accidently git throws following error. $ git checkout beta error: The following untracked working tree files would be overwritten by checkout:         app/SocialMedia/EmailShare.php         app/SocialMedia/EmailShareFactory.php Please move or remove them before you can switch branches. Aborting But when applying git status command no files to commit $ git status On branch abc nothing to commit, working directory clean Finally I checkout master branch. It was succefull. I think, because those files are still not in the master branch. After that I was able to checkout beta branch as well. Now that error happens again when I'm