My git repository has two branches, master
and bug
. I want to create a branch bug/rep
. So I run :
git branch bug/rep
This gives the error:
error: unable to resolve reference refs/heads/bug/rep: Not a directory fatal: Cannot lock the ref 'refs/heads/bug/rep'.
How can I create a sub branch from the bug
branch, like bug/rep
?
My git version is 2.3.2 on the Mac.
Click on Create Repository. As the repository is created, you can also create a branch before you publish/push the changes to GitHub. Select New branch from the Branch menu. Call it to feature and click on Create 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With