0

On the university cluster that I use, they use Open OnDemand for GUI file management system. I do some minor coding using the Editor that it has. I use git to manage my project. A strange thing is happening: when I do

git branch new_feature
git checkout new_feature

then open main.py using Open OnDemand, make a small change, save it, then

git checkout master
cat main.py

the change has been made on the master branch as well. It seems to me this has something to do with how Open OnDemand works. How can I use git, but also use Open OnDemand?

phd
  • 82,685
  • 13
  • 120
  • 165
BioBroo
  • 613
  • 1
  • 7
  • 21
  • 1
    https://stackoverflow.com/a/246298/7976758 – phd Mar 07 '23 at 23:33
  • 1
    Does this answer your question? [Modified files in a git branch are spilling over into another branch](https://stackoverflow.com/questions/246275/modified-files-in-a-git-branch-are-spilling-over-into-another-branch) – JDB Mar 08 '23 at 00:55
  • Looks Like I made the (common?) mistake of thinking of the branches as literal copies. – BioBroo Mar 08 '23 at 03:55

1 Answers1

1

I don't know what OnDemand would be doing but in strict git terms, as long as you do not commit a change, git will move that change along when you do a checkout with uncommitted changes (some conditions are checked which might get git to reject the checkout). Given that you are not explainig that you committed, I think that is the root cause.

eftshift0
  • 26,375
  • 3
  • 36
  • 60
  • How do I keep the two branches separate enough that I can run a program in `master`, which requires me to make small changes to a config file, all the while developing `new_feature` without `master` trying to use files I've modified in `new_feature`? – BioBroo Mar 08 '23 at 04:01
  • 1
    You need to _commit_ the changes to one branch, that is the whole point of branches, being able to have code/files that move in different directions. – eftshift0 Mar 08 '23 at 06:46
  • I'm new to git, but advice I saw recommended that I commit when I have a version I might want to come back to. But, from what you're saying, it looks like I'll need to buck the advice to be able to accomplish what I want to do. For example, I might need to commit an unfinished line of code so that I can return to master and run that code I want there. – BioBroo Mar 08 '23 at 11:19
  • 1
    You can also take advantage of the stash when you want to save something that is not ready for a commit. `git help stash` – eftshift0 Mar 08 '23 at 11:39
  • Still, there's the difficulty of the fact that I submit SLURM jobs to a queue in the cluster, and they may not run right away. I don't know when they'll run, and if I'm in `new_feature`, rather than `master`, they'll run on the wrong code. – BioBroo Mar 08 '23 at 14:00
  • Perhaps using separate worktrees? You can have more than one worktree per repo. – eftshift0 Mar 08 '23 at 14:12