1
user@LAPTOP-LNQB4U6E MINGW64 ~/store (master)
$ git branch
* master

user@LAPTOP-LNQB4U6E MINGW64 ~/store (master)
$ ls -l
total 0
-rw-r--r-- 1 user 197121 0 Jun 12 10:43 file1.py

user@LAPTOP-LNQB4U6E MINGW64 ~/store (master)
$ git branch part1

user@LAPTOP-LNQB4U6E MINGW64 ~/store (master)
$ git checkout part1
Switched to branch 'part1'

user@LAPTOP-LNQB4U6E MINGW64 ~/store (part1)
$ git branch
  master
* part1

user@LAPTOP-LNQB4U6E MINGW64 ~/store (part1)
$ ls -l
total 0
-rw-r--r-- 1 user 197121 0 Jun 12 10:43 file1.py
user@LAPTOP-LNQB4U6E MINGW64 ~/store (master)
$ git branch
* master

user@LAPTOP-LNQB4U6E MINGW64 ~/store (master)
$ ls -l
total 0
-rw-r--r-- 1 user 197121 0 Jun 12 10:43 file1.py

user@LAPTOP-LNQB4U6E MINGW64 ~/store (master)
$ git branch part1

user@LAPTOP-LNQB4U6E MINGW64 ~/store (master)
$ git checkout part1
Switched to branch 'part1'

user@LAPTOP-LNQB4U6E MINGW64 ~/store (part1)
$ git branch
  master
* part1

user@LAPTOP-LNQB4U6E MINGW64 ~/store (part1)
$ ls -l
total 0
-rw-r--r-- 1 user 197121 0 Jun 12 10:43 file1.py
abhiarora
  • 7,515
  • 3
  • 27
  • 46

1 Answers1

0

That seems expected:

  • either file1.py was not tracked (added/commited) to the master branch, and that private file would not disappear just because you are creating a branch

  • or file1.py was part of the master branch, and creating a new branch from there would start with the master branch content.

Only creating an orphan branch (git switch --orphan) would start with an empty content.

Note: if you are using Git 2.23 or more recent, use git switch, not the confusing git checkout old command.

VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283