title: How to maintain multiple independent stable git branches
body: <p>Here's a git problem. I'm making a <a href="https://github.com/globewalldesk/revuu" rel="nofollow noreferrer">programming study review app</a> in pure (command line) Ruby. This app allows the user to design and schedule reviews of programming tasks, manage the files in which the tasks are performed, and run the result automatically from the app. For these purposes, I don't need git when there's a single file. But most advanced and web programming tasks involve editing and using multiple files, and to manage that, <a href="https://stackoverflow.com/questions/53068195/any-gotchas-running-a-rails-installation-after-repeatedly-copying-it/">I need to use git</a>, and I'm not great with git.</p>
  
  <p>In the app, the maker of these more complex "repotasks" is expected to make questions based on a git branch (of his choice) of a repo (of his choice). So I figure what this requires is that, for each repo, there is a series of branches, each of which is maintained independently of each other, and each of which is relatively stable; and the app basically checks out branches as needed to answer questions. It <em>sounds</em> simple...</p>
  
  <p>The problems are:</p>
  
  <ul>
  <li><p>After I make new branches (by hand, with <code>git checkout -b branch_name</code>) and add new files, I seem to be prevented from checking out <em>some</em> previous branches. For example:</p>
  
  <p><code>$ git checkout foobar_JS_enabled_missing_prompt
  error: The following untracked working tree files would be overwritten by checkout:
      display_nodename.html
  Please move or remove them before you switch branches.
  Aborting</code></p></li>
  <li><p>I (think I) need to <code>git reset --hard</code> branches after a user finishes answering a question. But doing this seems to have inadvertently blanked a file I worked hard on in setting up a later branch. I think it's because I hard-reset an earlier branch in which said file was blank.</p></li>
  </ul>
  
  <p>The git interaction the app does (mostly using <a href="https://github.com/ruby-git/ruby-git" rel="nofollow noreferrer">ruby-git</a>) so far is:</p>
  
  <ul>
  <li>Actually create repos and branches by hand.</li>
  <li>List branches for question-makers to choose from.</li>
  <li><p>Checkout branches when they are chosen, using</p>
  
  <p><code>g = Git.open("data/repos/#{repo}")
  g.branch(branch).checkout</code></p></li>
  <li><p>Do a hard reset of a branch that a question is based on when the user starts answering the question, using:</p>
  
  <p><code>g = Git.open("data/repos/#{repo}")
  g.reset_hard</code></p></li>
  <li><p>I haven't done this yet, but I want to create an archive branch for each question, i.e., I want to let a question-answerer to review an old answer, then switch to the main branch for that question in order to create a new answer.</p></li>
  </ul>
  
  <p>Basically, I want frozen versions of each branch, but the process (described above) seems to create unwanted interactions. I thought branches were isolated from each other automatically. What am I doing wrong? What do I need to do in order to freeze the last-committed version of each branch, regardless of what happens in other branches, while I switch frequently between branches?</p>
  
  <p>UPDATE (11/18): I will leave this as a comment rather than an answer, because the question is a little obscure. I never realized that the index and tree are independent of branches. So my code actually had a few subtle bugs relating to the fact that I was letting my tree get unclean. In a couple of places, I needed to hard reset the code before letting an answerer start work on an answer, even if, most of the time, that isn’t necessary.  I also needed to hard reset the code after an answerer finishes.  Another thing I needed to do was to check what branch is currently checked out and switch to the right one ( I had already done this, but not everywhere I should’ve). </p>
  
  <p>Seems to be working now, and I’m not able to replicate the bugs anymore. </p>