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
Asked
Active
Viewed 65 times
1

VonC
- 1,262,500
- 529
- 4,410
- 5,250

Fahmida Orsi
- 11
- 1
1 Answers
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 branchor
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,262,500
- 529
- 4,410
- 5,250
-
Thanks for your reply. But this solution also gives me the same result.... – Fahmida Orsi Jun 17 '20 at 01:40
-
@FahmidaOrsi What version of Git are you using? – VonC Jun 17 '20 at 05:59
-
git version 2.27.0.windows.1 – Fahmida Orsi Jun 18 '20 at 11:47
-
@FahmidaOrsi in a git bash session, this should work. – VonC Jun 18 '20 at 12:45