How does one add a new folder to a branch in git without having that folder show up in the master branch?
e.g.
git branch myNewBranch
git checkout myNewBranch
mkdir foo
git checkout master
ls
the myNewBranch directory is also added to master
Just because you created the folder git will not automatically start version controlling it. The folder you created is unknown to git so git will not touch it.
git init #create repo
touch file1.txt
git add file1.txt
git commit -m 'initial commit'
git branch newBranch
git checkout newBranch
mkdir folder
touch folder/file2.txt
git add folder #tell git we want to track the folder
git commit -m 'second commit'
git checkout master
# folder/file2.txt is not available as expected.
Edit: To clarify the folder in your example was not added to master, it actually was not added to any branch.
It would seem you have 2 misconceptions that are confusing you.
add
and commit
a file before Git will do anything to that file (like modify or remove it when you checkout a different branch)..gitignore
in that directory and commit that.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