Reputation: 1234
I was working on a master branch. Had a new idea, so I went with:
git checkout -b new_branch_name
Did some changes on the new branch and then switched back to the master. All the changes I did on new branch were applied to master. What should I do to prevent that?
Upvotes: 2
Views: 1438
Reputation: 52196
If you didn't add or commit anything :
# switch to your new branch
git checkout new_branch_name
# confirm that your changes are still there :
git status
# commit on your new branch
git add ...
git commit ...
# go back to master
git checkout master
Upvotes: 1
Reputation: 5434
When you do not commit changes to the new branch, the changes are cached and accessible via the parent branch (master
in this case)
To prevent this, you should always git add [FILE]
and git commit
before switching to the parent branch.
In case you do switch before committing, simply switch back to the new branch, add the changed file(s) and commit
Upvotes: 3
Reputation: 44980
Since you didn't add
or commit
the new files they are untracked and outside of your git repo. They only exist on the filesystem. You can delete all of them using git clean -f -d
to restore the clean state of your repo.
Upvotes: 2