How to add new folder to git branch without adding it to master
git, git-branch
Solution
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.
Problem
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