Search code examples
gitgithubgitlabgitignore

Don't remove local file which is in .gitignore while change branch


I have a branch named A and I created some files and folders which added to the .gitignore file before pushing them into repo.

I wanna keep them in my editor while I change to the new branch B which doesn't contain these files and folders.

Can anyone help me how to achieve this goal?


Solution

  • I try to answer you point per point.

    I have a branch named A and I created some files and folders which added to the .gitignore file before pushing them into repo.

    You are stating that you ignored some files and folders before pushing to remote, so you have them as untracked locally. Is it right?

    I wanna keep them in my editor while I change to the new branch B which doesn't contain these files and folders.

    If what I stated in the previous point answer you have some untracked items. In that situation you can freely switch branch without loosing them, thus keeping them opened into the editor.

    Can anyone help me how to achieve this goal?

    If my guesses are right, you should simply issue git checkout B.

    Let me know it it is all right.

    Edit:

    Try again with:

    git stash save -u
    git checkout B
    git stash pop