I'm new to Git.
i created a branch off of master. I'm working in that branch. i then go and create a new file in that new branch. I then switch back to master to view something.
i see that file that i just added when i switch over to master as a file to add? I don't want to add that file to the master branch. Aren't those branches supposed to be completely independent of each other? I added it to the new branch, not the master branch. How can i separate the branches?
If you git add a file, but then switch branches before committing, the staged addition will be carried over to the new branch (just like any other staged changes).
You use git add . to copy all files in the current directory or any sub-directory into the index,2 so that they can be committed. This includes this new file x that you just created in your work-tree. Your index is now ready for committing.
Yes you can say git add *. py Make sure you have done git init before doing this. To add all files in a folder you can simply say git add .
Set “–assume-unchanged” to a path to exclude to check on git commit and it will exclude your file from git commit. You will need to use the git update-index and –assume-unchanged to exclude files from git commit.
If you git add
a file, but then switch branches before committing, the staged addition will be carried over to the new branch (just like any other staged changes). You probably wanted to commit
before switching branches.
Any uncommitted changes, including files that are not added to the repository, are preserved when switching the working copy between branches.
Just making a new file does not automatically add it to the repository, you have to do a git add myFile
(and eventually commit
that).
Or, looking at it the other way, even if the file stays around in your working copy when you switch branches, it won't become part of those other branches unless you explicitly add and commit them there, either.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With