Error changing master branch: my local changes will be overwritten with checkout

This question is similar to this , but more specific.

I have a project with two branches ( staging and beta ).

I develop on staging and use the master branch to fix errors. Therefore, if I work on creation and see an error, I proceed to the master branch:

 git checkout master 

and do the following:

 git add fileToAdd git commit -m "bug fixed" 

and then I merge with two branches:

 git checkout staging git merge master git checkout beta git merge beta 

And it does not matter if there are other files on the working tree.

But now, when I try to switch to the master branch, I get an error message :

 error: Your local changes to the following files would be overwritten by checkout: src/Pro/ConvocationBundle/Controller/DefaultController.php Please, commit your changes or stash them before you can switch branches. Aborting 

I thought I should delete the file from the staging area:

 git reset HEAD src/Pro/ConvocationBundle/Controller/DefaultController.php 

but I get the same error. If I do git status , I get No changes to commit

+48
git git-checkout
Mar 15 '14 at 13:01
source share
3 answers

Your error appears when you change the file, and the branch you are switching to has changes for this file (from the last merge point).

Your parameters, as I see it, are commit, and then make changes to this commit with additional changes (you can change the commit in git if they are not push ed); or - use the cache:

 git stash save your-file-name git checkout master # do whatever you had to do with master git checkout staging git stash pop 

git stash save will create a stash that contains your changes but is not associated with any commit or even a branch. git stash pop will apply the latest registry entry to your current branch, restoring saved changes and removing it from stash.

+57
Mar 15 '14 at 14:20
source share

I ran into the same problem and solved it

 git checkout -f branch 

and its specification is pretty clear.

-f, --force

When switching branches, continue even if the index or working tree is different from HEAD. This is used to remove local changes.

When checking paths from an index, do not fail with unauthorized entries; instead, ignored entries are ignored.

+43
Sep 14 '15 at 1:27
source share

You can force check your branch if you do not want to make local changes.

 git checkout -f branch_name 
+3
Oct 05 '15 at 10:51
source share



All Articles