5

I want a create git branch like develop/user1/issue1 on remote repository how can I create that?

- master => /origin/master
- develop => /origin/develop
    - user1 => /origin/develop/user1
         - issue1 => /origin/develop/user1/issue1
         - issue2 => /origin/develop/user1/issue2
         - issue3 => /origin/develop/user1/issue3
    - user2 => /origin/develop/user2
         - issue4 => /origin/develop/user1/issue4
         - issue5 => /origin/develop/user1/issue5
Anshul Goyal
  • 73,278
  • 37
  • 149
  • 186
  • just create a branch named `develop/user1/issue1` and push it on `origin` – CharlesB Sep 12 '13 at 11:25
  • # git checkout -b develop/user1 error: unable to resolve reference refs/heads/develop/user1: Not a directory fatal: Failed to lock ref for update: Not a directory – Kyounghwan Kim Sep 12 '13 at 11:32
  • 3
    possible duplicate of [Using the slash character in Git branch name](http://stackoverflow.com/questions/2527355/using-the-slash-character-in-git-branch-name) – Nevik Rehnel Sep 12 '13 at 11:40

1 Answers1

19

Basically you can't create the structure as you are proposing.

Why?

Because when you have a branch with slashes in it, it gets stored as a directory hierarchy under .git/refs/heads

How to verify

Say you don't have any branches in an empty directory.

So you create a dummy repository using

touch testfile && git init && git add . && git commit -m "initializing"`.

Next, run the git branch command to create some branches as you suggested.

git branch origin/master
git branch origin/develop/user1
git branch origin/develop/user2/issue4

Now, cd into the .git/refs/heads directory using cd .git/refs/heads and do a ls -la

You will find that git has created the following directory structure.

master (file)
origin (directory)
|_master (file)
|_develop (directory)
   |_user1 (file)
   |_user2(directory)
     |_issue4 (file)

If now you try creating a branch using git branch origin/develop/user1/issue1, it will throw the error because a file named user1 already exists while your command needs it to be a directory.

Anshul Goyal
  • 73,278
  • 37
  • 149
  • 186
  • Adding to the answer, as branches are seen as directories and files, you cannot have a branch name with slashes which "sub-path" already exists a branch name. If you deleted the /origin/develop/user1 branch, you'd be able to create several issue branches for user1. That's what I do at more work. – Alan Evangelista Nov 18 '15 at 19:11