1

From the default master branch, I created another branch division_feature using

git branch division_feature

After that I switched to this new branch.

git checkout division_feature

My working branch was set to division_feature and I created a folder called division_data. I added and committed this folder to the branch.

git add .
git commit -m "Added a branch specific folder"

According to the official documentation, now only my division_feature branch should have this folder in my branch. But when I switched my repository back to master, the division_data directory was there in the master branch as well.

git checkout master
ls

the division_data directory was there which I think should not be happening as the git documentation clearly says.

That command did two things. It moved the HEAD pointer back to point to the master branch, and it reverted the files in your working directory back to the snapshot that master points to.

Can you please guide me where I am going wrong?

Kashif Nazar
  • 20,775
  • 5
  • 29
  • 46
  • Were there any untracked files in your new directory? (Including temporary files like editor autosaves, etc.) – CB Bailey Apr 05 '14 at 11:58

2 Answers2

3

You didn't add the folder, because it is an empty folder.

It remains as a private data (not versioned), which is why you see it when you checkout the first branch.

You must add at least one file in that folder for said file to be versioned in one branch, and not visible in the other (as in "How do I add an empty directory to a git repository").

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

To create a new branch I use the following commands from "master" branch:

git checkout -b division_feature

git add .

To verify if all files are added, try:

git status

Then:

git commit -m "Added a branch specific folder"

git checkout master
MrDevel
  • 166
  • 2
  • 13