How to create a sub branch?
In git, branches correspond to actual files in a hierarchy in the .git
subdirectory. If you create a branch named bug/sub
, git will first create a folder .git/refs/heads/bug
(if it doesn't already exist) and within that folder it will create a file named sub
which is the branch. Branch names are presumed to resolve within .git/refs/heads
, so refs/heads
+ bug/sub
resolves to a real place in the file system.
The trouble that you're encountering comes from your file system. Since you already have a branch called bug
, in .git/refs/heads
there is already a file named bug
. Creating the sub branch as outlined above would require the file system to create a new folder named bug
, but it can't because there is already a file there named bug
.
In brief, you're free to create a hierarchy of branches, but higher-level nodes of your hierarchy can't be branches in their own right.
for creating a new sub branch git checkout -b <sub-branch-name>
// sub branch will automatically created at the time of push
for pushing file on sub branch created earlier git push -u origin <sub-branch-name>
-u for setting upstream parameter
here origin is the master branch, added with
git add remote origin master https://github.com/<ur-name>/repoName.git
checkout the name of branches
git branch