Stop Mixing Up Branches in Git

Viewed 20

In my work, there are many independent bugs or necessary configuration changes being reported all the time. I have a copy of the repository which contains the code I need to edit to accomplish these changes. These changes are all independent of each other. I would like to be able to make changes on one branch, save them, and then switch to a different branch and work on unrelated changes without bringing the previous changes with me.

I thought that this pattern was more or less what git was designed to do, but git doesn't seem to keep the branches separate. I just executed the following:

git checkout -b me/new-branch
vim <file>
git add <file>
git commit <file> -m "message"
git push origin me/new-branch

And the resulting PR had 3 commits in it: the newest one, and two random ones from a week ago. This is a constant problem; I can't figure out why any particular commit ends up in any particular PR. The commits being put into multiple PRs aren't necessarily the most recent ones I've been working on. I can use the same git commands three times in a row, and two of the branches I create will be "clean" (not include extra commits when I push them) and the third one will have multiple commits in it. I'm sure git is behaving as intended, but I have no idea what it's doing or why.

Here is exactly what I am looking for:

  1. I'm clearly missing some very basic principle of how git works. What is it?
  2. Is there a series of git commands I can use to see if I currently have work that will follow me from one branch to another? I've been using git status but that doesn't work.
  3. What is the intended way for me to save my work on a current branch so that I can pick it up later without taking it with me when I switch to working on a different branch?
  4. How can I consistently make new branches that are just copies of main with no other changes?
0 Answers
Related