Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git branching while files are opened

Tags:

git

vim

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?

like image 859
gath Avatar asked Jan 07 '11 10:01

gath


People also ask

Can you have two branches open at the same time git?

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.

What are the three types of branching in git?

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.


2 Answers

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.

like image 117
Xavier T. Avatar answered Sep 22 '22 14:09

Xavier T.


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.

like image 23
Sylvain Defresne Avatar answered Sep 22 '22 14:09

Sylvain Defresne