In git, is there a simple way of introducing an unrelated branch to a repository?

前端 未结 9 2215
被撕碎了的回忆
被撕碎了的回忆 2020-11-22 06:11

While helping a friend with a git problem today, I had to introduce a branch that needed to be totally separate from the master branch. The contents of this bra

9条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-22 07:09

    Although the solution with git symbolic-ref and removing index works, it might be conceptually cleaner to create new repository

    $ cd /path/to/unrelated
    $ git init
    [edit and add files]
    $ git add .
    $ git commit -m "Initial commit of unrelated"
    [master (root-commit) 2a665f6] Initial commit of unrelated
     1 files changed, 1 insertions(+), 0 deletions(-)
     create mode 100644 foo
    

    then fetch from it

    $ cd /path/to/repo
    $ git fetch /path/to/unrelated master:unrelated-branch
    warning: no common commits
    remote: Counting objects: 3, done.
    Unpacking objects: 100% (3/3), done.
    remote: Total 3 (delta 0), reused 0 (delta 0)
    From /path/to/unrelated
     * [new branch]      master     -> unrelated-branch
    

    Now you can delete /path/to/unrelated

提交回复
热议问题