Error when changing to master branch: my local changes would be overwritten by checkout

Manolo

This question is similar to this one, but more specific.

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

I develop on staging, and use the master branch to fix bugs. So if I'm working on staging and I see an error, I change to master branch:

git checkout master

and do the stuff:

git add fileToAdd
git commit -m "bug fixed"

and then I merge with both branches:

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

And doesn't matter if there are other files on the working tree.

But now, when I try to change to the master branch, I'm getting an error:

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 that I should remove the file from the staging area:

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

but I'm getting the same error. If I do git status I get No changes to commit

keltar

Your error appears when you have modified a file and the branch that you are switching to has changes for this file too (from latest merge point).

Your options, as I see it, are - commit, and then amend this commit with extra changes (you can modify commits in git, as long as they're not pushed); or - use stash:

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 stash that contains your changes, but it isn't associated with any commit or even branch. git stash pop will apply latest stash entry to your current branch, restoring saved changes and removing it from stash.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Homebrew update error that local changes would be overwritten

From Dev

Couldn't merge origin/master: error: Your local changes to the following files would be overwritten by merge

From Java

How do I ignore an error on 'git pull' about my local changes would be overwritten by merge?

From Dev

git checkout master automatically moves my other not committed branch changes

From Dev

How do I handle the Git error "Your local changes to the following files would be overwritten by merge"

From Dev

git error on rvm update: Your local changes to the following files would be overwritten by merge on rvm get head command

From Dev

How do I handle the Git error "Your local changes to the following files would be overwritten by merge"

From Dev

git checkout < branch > failure for local changes

From Dev

error: The following untracked working tree files would be overwritten by checkout

From Dev

Your local changes to the following files would be overwritten by merge

From Dev

git push: local changes to the following files would be overwritten by merge

From Dev

Git workflow: "Your local changes would be overwritten by merge"

From Dev

Is there a way to pull the master changes from my branch?

From Dev

Transfer changes from "master" to my branch

From Dev

Replace remote master branch with my local

From Dev

files changes when merge branch to master

From Java

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

From Dev

How to rebase master and integrate [master] changes into my branch?

From Dev

Checkout second Git branch without losing local changes

From Dev

Local uncommited changes in master. Need to switch to another branch

From Dev

github. How would one merge all changes from the master branch into another branch?

From Dev

Can't pop git stash, 'Your local changes to the following files would be overwritten by merge'

From Dev

How to get changes from branch pushed to master on local branch as uncommitted changes?

From Dev

Pulling changes of another branch and replay my local changes over them

From Dev

Pulling changes of another branch and replay my local changes over them

From Dev

Stop git from bringing changes to master into my branch?

From Dev

merge master to my feature branch overwrites changes in git

From Dev

git checkout branch but remains in master

From Dev

Cannot checkout master branch from branch with submodule

Related Related

  1. 1

    Homebrew update error that local changes would be overwritten

  2. 2

    Couldn't merge origin/master: error: Your local changes to the following files would be overwritten by merge

  3. 3

    How do I ignore an error on 'git pull' about my local changes would be overwritten by merge?

  4. 4

    git checkout master automatically moves my other not committed branch changes

  5. 5

    How do I handle the Git error "Your local changes to the following files would be overwritten by merge"

  6. 6

    git error on rvm update: Your local changes to the following files would be overwritten by merge on rvm get head command

  7. 7

    How do I handle the Git error "Your local changes to the following files would be overwritten by merge"

  8. 8

    git checkout < branch > failure for local changes

  9. 9

    error: The following untracked working tree files would be overwritten by checkout

  10. 10

    Your local changes to the following files would be overwritten by merge

  11. 11

    git push: local changes to the following files would be overwritten by merge

  12. 12

    Git workflow: "Your local changes would be overwritten by merge"

  13. 13

    Is there a way to pull the master changes from my branch?

  14. 14

    Transfer changes from "master" to my branch

  15. 15

    Replace remote master branch with my local

  16. 16

    files changes when merge branch to master

  17. 17

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

  18. 18

    How to rebase master and integrate [master] changes into my branch?

  19. 19

    Checkout second Git branch without losing local changes

  20. 20

    Local uncommited changes in master. Need to switch to another branch

  21. 21

    github. How would one merge all changes from the master branch into another branch?

  22. 22

    Can't pop git stash, 'Your local changes to the following files would be overwritten by merge'

  23. 23

    How to get changes from branch pushed to master on local branch as uncommitted changes?

  24. 24

    Pulling changes of another branch and replay my local changes over them

  25. 25

    Pulling changes of another branch and replay my local changes over them

  26. 26

    Stop git from bringing changes to master into my branch?

  27. 27

    merge master to my feature branch overwrites changes in git

  28. 28

    git checkout branch but remains in master

  29. 29

    Cannot checkout master branch from branch with submodule

HotTag

Archive