Is it advisable to switch branches in GIT when files are opened in your editor?
I have opened my project files in VIM on a number of tabs, and I want to quickly switch to a different branch, do I have to keep on closing my projects, switch a branch then reopen my project?
You can have many branches in your repository, but only one of these will be "checked out" as the working-tree so that you can work on it and make changes. git worktree adds the concept of additional working trees. This means you can have two (or more) branches checked-out at once.
The two primary branches in Git flow are main and develop. There are three types of supporting branches with different intended purposes: feature, release, and hotfix.
Vim should warn you, but if you want to be sure to reload every open buffer you can type:
:bufdo e
:e
will reload a file, :bufdo e
will reload every open buffer.
This can be a problem if your editor does not warn you when you try to save a file when it has been changed in the filesystem since it has been opened as you can lose work in the case.
There is also a potential problem on Windows as the editor may lock the file. If this is the case, git will be unable to update it and the switch will fail, leaving the working directory in an indeterminate state.
Apart from those issues (risk of losing change if you have unsaved modification, risk of failure if your editor is locking files), there is no problem using git command while you have files opened in your editor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With