2

Say I have two bash terminals open in the same git repository on branch main.

In the one, I start some process that takes a while to run, storing the results in a subdirectory /data every 2 seconds.

Then, in the other window, I call git checkout otherbranch to change branches.

Will the first window continue the rest of the process on the first branch, storing all results in /data on main, then switch branches on completion? Or will the first chunk of the results be written to /data on main, while others are written to /data on otherbranch?

pmhalvor
  • 31
  • 2
  • Git does not promise *not* to `rm -rf ./data` during the `git checkout otherbranch` (depending on conditions). If it does so, your output files may be lost. Git's checkout code strives to do as few file-system operations as possible for *speed* purposes, though, so depending on what files, if any, it needs to *replace* in `./data`, you might get away with this. The short answer is: for safety, don't do it. – torek Aug 30 '21 at 11:36
  • 1
    [Two](https://stackoverflow.com/q/2048470/1256452) [related](https://stackoverflow.com/q/51411897/1256452) questions... – torek Aug 30 '21 at 11:39

1 Answers1

0

Will the first window continue the rest of the process on the first branch, storing all results in /data on main, then switch branches on completion?

Yes, the process started in the first terminal will continue. However, depending on whether the files stored in /data are previously tracked by Git or not, one of two things will happen:

  1. If the files are new, they will appear in the working directory as untracked.
  2. If the files are tracked, Git might refuse to switch branch if those files have conflicting changes in otherbranch. If not, they will simply appear as modified in the working directory.

In any case, it's important to point out that Git doesn't store files in branches, but rather in tree structures referenced by individual commits. This means that the files in /data won't become part of either branch until you commit them.

Enrico Campidoglio
  • 56,676
  • 12
  • 126
  • 154