1

I was working in a branch "test" and took pull and now I am updated as per origin.

git checkout develop

I checkout to branch "develop" which is behind origin/develop and I copy made some changes in code. Now I run:

 git status

I got many untracked file and not staged files as I was ahead when I working in branch "test". Now I just want to checkout back to test branch and push my changes. My changes are little so I can revert and redo them. But how to switch branch because I get error:

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

All untsaged and untracked files

Please move or remove them before you switch branches.

Aborting

Need help so that I can get back to test branch and redo my changes.

Alwaysalearner
  • 3,137
  • 9
  • 45
  • 85
  • 1
    Possible duplicate of [The following untracked working tree files would be overwritten by checkout](https://stackoverflow.com/questions/4858047/the-following-untracked-working-tree-files-would-be-overwritten-by-checkout) – phd Jul 11 '18 at 07:04

1 Answers1

2

in this situation stash is your best friend - https://git-scm.com/docs/git-stash

Here is an example of how you can resolve it, I have gone from the step when you checked out develop

git checkout develop
git stash 
git checkout test
git stash pop
git add .
git commit -m 'YOUR MESSAGE'
git checkout develop

that should do it for you!

Josh Stevens
  • 3,445
  • 1
  • 12
  • 21
  • Thanks a ton @josh for taking time out to answer this. I have followed https://stackoverflow.com/questions/1146973/how-do-i-revert-all-local-changes-in-git-managed-project-to-previous-state https://stackoverflow.com/questions/22620393/various-ways-to-remove-local-git-changes/44761452 to find solution to my problem and similar to ur solution I used git checkout . and git stash -u and git checkout test. – Alwaysalearner Jul 11 '18 at 08:41