-1

I'm new using git branches. What I want to do is a new feature keeping the original master in case I need to go back and do something else from there.

For this purpose I did the following:

git branch new feature
git checkout newfeature

From newfeature branch, I made a fair amount of changes (I modified 78 files). Here is a summary of the git status:

On branch newfeature
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   //a long list of 60 files

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        // a long list of 18 files

no changes added to commit (use "git add" and/or "git commit -a")

What I didn't expect is that when I go back to master with the git checkout master command, I see all the changes as if I were in the newfeature branch. Here is a summary of the git status of the master:

On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
            modified:   //a long list of 60 files

Untracked files:
  (use "git add <file>..." to include in what will be committed)
            // a long list of 18 files

no changes added to commit (use "git add" and/or "git commit -a")

How can I switch between the original master (which should not have the changes) and the newfeature (which contains the changes to all 78 files)?

David L
  • 1,134
  • 7
  • 35

1 Answers1

2

How can I switch between the original master (which should not have the changes) and the newfeature (which contains the changes to all 78 files)?

Git is about commits. A branch is a commit. You need to make a commit.

While on the newfeature branch say

git add .
git commit -m 'your message here'

Now newfeature is a commit containing the changed versions of those files. So changing to the master commit...

git switch master

...and back to the newfeature commit...

git switch newfeature

...will alternate as you were hoping.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • And read https://www.biteinteractive.com/picturing-git-conceptions-and-misconceptions/ – matt Apr 06 '23 at 23:43