gitgatsbygit-branchgit-status

Gatsby develop V4 won’t switch between git branches


I have created a new git branch in my GatsbyJS project to work on a new feature, then running "gatsby clean" + "gatsby develop" to view the update, if I shut down the server and change back (checkout) to the master/main branch and run again "gatsby clean" + "gatsby develop" I can still see the updated version. Isn’t the browser supposed to show the original version without any changes?

I ran "gatsby clean" before "gatsby develop" everytime I switch branch and used two diferent browsers.

Another thing that I noticed (maybe this is ok), when I check "git status" I can see that the same file with the update is waiting to be commited on both branches.

As a side note I have basic gatsby-conf and gatsby-browser configuration


Solution

  • Clean your cache by running:

    gatsby clean
    

    This will delete your /public and your .cache folder. Keep in mind that the code you are seeing when building your site is under /public folder, so it makes sense to remove it to see the previous changes.

    As a personal option, I normally tweak my develop command by adding a gatsby clean before, just to avoid this kind of issues in the package.json.

    If you change something, and then you check out to another branch, the changes will come with you to the branch because they are not committed or staged. Git is aware that there's a file changed, but they're not attached to anything locally. If you want that changes to "don't come with you" when you check out you should commit/push them, or running a git stash, check out to the new branch and whenever you want you can recover them by running git stash pop (or discard them with git checkout .)