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.
-
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
) thepush
in the next step would fail with"error: refusing to update checked out branch: refs/heads/master"
-
copy source branch to master as master to new repository
> cd source-clone > git push ../new-bare-repo source-branch:master > cd ..
-
clone from the new bare repository
> git clone ./new-bare-repo new-clone
-
push to github
> cd ./new-clone > git remote add origin https://github.com/<user>/<remote-repo>.git > git push -u origin master
-
cleanup
now that the new repository is on github the
new-bare-repo
is no longer needed.