简体   繁体   中英

How do I change a feature branch of a local git repo without changing the master branch?

I have a project like this, that I've cloned from github.

top
   --init.py

I've created a branch feature_1, but whenever I checkout the branch, and add a file to the top level directory (ie test.py), the master branch is changed...

can anyone suggest reasons why? If it helps, I'm using pycharm...

You could run a

git stash

or alternatively a

git add <filename>
git commit -m "<my commit message>"

These options would ensure that your feature branch has the local file either in a dirty working directory ( git stash ) or in a commit before swapping over to your master branch.

If you're not committing, you're not changing any branch, you're just changing the files in your working tree. Make your changes and commit them to the feature branch. That will make those changes part of the feature branch, and they won't appear on master. As long as you don't commit, git won't touch your changes at all, even if you switch branches. The rule with git is commit early and often.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM