create new git repository from a branch

how to copy a git branch to its own git repository as master branch

The following steps create a new git repository with a master branch from a branch of a source repository.

The steps refer to a source repository with the name source-clone and a source branch with the name source-branch. After finishing the steps there is a new-clone clone from the new repository new-bare-repo with a master branch including the full history.

  1. create new repository folder & init git in new repository

    > mkdir new-bare-repo
    > git --bare init new-bare-repo

    --bare creates a repository without a workspace, otherwise (without --bare) the push in the next step would fail with

    "error: refusing to update checked out branch: refs/heads/master"
  2. copy source branch to master as master to new repository

    > cd source-clone
    > git push ../new-bare-repo source-branch:master
    > cd ..
  3. clone from the new bare repository

     > git clone ./new-bare-repo new-clone
  4. push to github

     > cd ./new-clone
     > git remote add origin https://github.com/<user>/<remote-repo>.git
     > git push -u origin master
  5. cleanup

    now that the new repository is on github the new-bare-repo is no longer needed.