I have a project with 2 branches: staging and beta.I develop on staging, and also use the master branch to deal with bugs. For this reason if I"m functioning on staging and also I watch an error, I readjust to grasp branch:

git checkout masterand carry out the stuff:

git add fileToAddgit commit -m "bug fixed"and then i merge with both branches:

git checkout staginggit unify mastergit checkout betagit merge betaAnd doesn"t matter if there are other files on the working tree.

You are watching: Error: your local changes to the following files would be overwritten by checkout:

But now, when I shot to change to the master branch, I"m acquiring an error:

error: her local transforms to the following documents would be overwritten by checkout:src/Pro/ConvocationBundle/Controller/DefaultController.phpPlease, go your transforms or stash them prior to you can switch branches.AbortingI thought that I need to remove the record from the staging area:

git reset HEAD src/Pro/ConvocationBundle/Controller/DefaultController.phpBut I"m gaining the same error. If I do git status, I gain No transforms to commit


git git-merge git-checkout
re-superstructure
boost this concern
follow
edited Aug 29 in ~ 15:41
*

ouflak
2,34755 yellow badges3737 silver badges4545 bronze badges
asked Mar 15 "14 at 13:01
*

ManoloManolo
18.5k1717 yellow badges7171 silver- badges119119 bronze badges
7
| present 2 much more comments

8 answer 8


energetic oldest Votes
199
I encountered the exact same problem and solved it by

git checkout -f branchand that is specification is quite clear.

-f, --force

When switching branches, proceed also if the index or the working tree differs from HEAD. This is used to throw away local changes.

When discovering paths from the index, carry out not fail upon unmerged entries; instead, unmerged entries space ignored.


re-superstructure
boost this answer
monitor
edited Feb 26 "18 in ~ 9:13
answered Sep 14 "15 at 1:27
*

KikiYuKikiYu
2,36511 gold badge1111 silver badges1313 bronze badges
5
include a comment |
163
Your error appears when you have modified a document and the branch the you are switching come has changes for this file too (from recent merge point).

Your options, together I see it, are - commit, and then amend this commit through extra transforms (you deserve to modify commits in git, as lengthy as they"re not pushed); or - usage stash:

git stash conserve your-file-namegit checkout master# do everything you had to do with mastergit checkout staginggit stash popgit stash conserve will produce stash that contains your changes, but it isn"t connected with any commit or also branch. Git stash popular music will apply latest stash entry come your current branch, restoring conserved changes and removing the from stash.


re-publishing
improve this prize
follow
edited Jun 10 "16 at 16:39
*

Marcus Leon
51.9k114114 gold badges282282 silver- badges418418 bronze badges
answer Mar 15 "14 in ~ 14:20
*

keltarkeltar
16k22 gold badges3131 silver badges4040 bronze badges
20
| present 15 much more comments
15
You can pressure checkout your branch, if you perform not desire to commit your regional changes.

git checkout -f branch_name
re-superstructure
boost this price
follow
edited Jul 24 "16 in ~ 17:46
SidOfc
4,39633 yellow badges2525 silver- badges4747 bronze badges
answered Oct 5 "15 at 10:51
Deepika PatelDeepika Patel
2,31522 gold badges1818 silver- badges1212 bronze title
5
add a comment |
9
ns encountered the exact same problem and solved the by

git checkout -f branch

Well, be mindful with the -f switch. You will certainly lose any kind of uncommitted transforms if you use the -f switch. If there may be some use situations where it is valuable to usage -f, in most cases, you might want to stash her changes and also then move branches. The stashing procedure is described above.


share
enhance this answer
monitor
edited Jul 31 "18 in ~ 1:13
answer Jul 31 "18 at 1:07
BeNizaBeNiza
46744 silver- badges33 bronze title
1
add a comment |
5
This error happens once the branch you are switching to, has changes that your present branch doesn"t have.

If you space seeing this error when you shot to switch to a brand-new branch, climate your present branch is more than likely behind one or much more commits. If so, run:

git fetchYou should also remove dependencies i beg your pardon may additionally conflict with the location branch.

For example, because that iOS developers:

pod deintegratethen shot checking the end a branch again.

If the preferred branch isn"t brand-new you deserve to either cherry choose a commit and also fix the conflicts or stash the changes and then settle the conflicts.

See more: Gary With Da Tea Real Name, Net Worth, Gary With Da Tea

1. Git Stash (recommended)

git stashgit checkout git stash apply2. Cherry choose (more work)

git include git commit -m "Your message"git logCopy the sha of your commit. Climate discard unwanted changes:

git checkout .git checkout -- . Git clean -f -fd -fxMake sure your branch is approximately date:

git fetchThen checkout come the wanted branch

git checkout then cherry choose the other commit:

git cherry-pick now fix the conflict.

Otherwise, her other alternative is come abandon your present branches changes with:

git checkout -f branch