2

I searched StackOverflow for similar questions but it always seems people are trying to get from their branch onto master. For me it's the opposite. I'm on master and trying to checkout to a branch that has already been pushed.

When I do:

git checkout mybranch

I get:

error: Your local changes to the following files would be overwritten by checkout:
    db/structure.sql
Please commit your changes or stash them before you switch branches.
Aborting

I've tried with:

git checkout -f mybranch

but I get the message:

error: Entry 'db/structure.sql' not uptodate. Cannot merge.

If I try to stash or commit, it makes no difference:

git stash
No local changes to save

git checkout mybranch
error: Your local changes to the following files would be overwritten by checkout:
    db/structure.sql
Please commit your changes or stash them before you switch branches.
Aborting

or

git commit
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

git checkout mybranch
error: Your local changes to the following files would be overwritten by checkout:
    db/structure.sql
Please commit your changes or stash them before you switch branches.
Aborting

git submodule status returns nothing, and git status -u returns:

On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

Any suggestions as to what to do to fix this?

DaniG2k
  • 4,772
  • 36
  • 77
  • Tried committing or stashing ? – Utsav Patel Feb 28 '19 at 06:26
  • Yes I’ve tried both stashing and committing. – DaniG2k Feb 28 '19 at 06:26
  • 1
    Possible duplicate of [Error when changing to master branch: my local changes would be overwritten by checkout](https://stackoverflow.com/questions/22424142/error-when-changing-to-master-branch-my-local-changes-would-be-overwritten-by-c) – bhatnaushad Feb 28 '19 at 06:27
  • I specifically pointed out I'm on master trying to change to a branch that has been pushed already, not the other way round. – DaniG2k Feb 28 '19 at 06:28
  • Is `db/structure.sql` tracked or untracked? Is it part of a submodule? – kowsky Feb 28 '19 at 06:43
  • `db/structure.sql` is part of the workdir so is tracked afaik. – DaniG2k Feb 28 '19 at 06:44
  • Can you provide the output of `git submodule status` and `git status -u`? – kowsky Feb 28 '19 at 06:49
  • @kowsky sure thing I've updated the question – DaniG2k Feb 28 '19 at 06:50
  • The questions [here](https://stackoverflow.com/questions/1248029/git-pull-error-entry-foo-not-uptodate-cannot-merge) and [here](https://stackoverflow.com/questions/25597104/git-pull-error-your-local-changes-to-the-following-files-would-be-overwritten-b) seem to adress simlar issues. Do any of the suggested solutions work? – kowsky Feb 28 '19 at 06:56
  • No they don't work. I've tried with `git checkout master; git fetch; git rebase origin/master` and with `git reset --hard` but nothing works, when trying to switch to that branch I get the same error – DaniG2k Feb 28 '19 at 07:00
  • 1
    It does not matter what the *branch names* are. What matters are the *files in the index, work-tree, and commits* and whether you have set the assume-unchanged and/or skip-worktree bits on entries in your index. – torek Feb 28 '19 at 07:20
  • Possible duplicate of [Git checkout fails with because local changes ... without local changes?](https://stackoverflow.com/questions/51446801/git-checkout-fails-with-because-local-changes-without-local-changes) – phd Feb 28 '19 at 09:51

0 Answers0