How do I create a new GitHub repo from a branch in an existing repo?

前端 未结 6 1421
既然无缘
既然无缘 2020-12-02 03:21

I have master and new-project branches. And now I\'d like to create a brand new repo with its master based on the new-project branch.

6条回答
  •  难免孤独
    2020-12-02 04:12

    git clone -b new-project /path/to/repo /new/repo/path
    

    Edit: Within GitHub, you can “fork” the repo, then go to the Admin tab in your clone. Beneath “Repository name” and “Visibility” is “Default Branch” with a drop-down menu of branches. Choose new-project.

    Re-edit: I just realized it’s the master branch you want set, not just the “default” branch. So…

    • On GitHub, clone them/repo to you/repo.
    • Run git clone git@github.com:you/repo.git
    • Start gitk.
    • [You might want to create an old-master branch so you don’t lose track of the old commits.]
    • Find most recent commit on the new-project branch, right-click on the commit message, and select “Reset master branch to here”. (You can also do this at the command line using git-reset, but I haven’t figured out the correct invocation.)

    Your next push up to your GitHub repo will need to be done with the --force option, but otherwise you’re done.

    If it’s one of your own repos you’re doing this to…

    • Run git clone git@github.com:you/orig.git
    • Run git clone orig copy
    • As I described above, but from within the local copy repo, reset the master branch to where you want it.
    • Create the empty GitHub project you/copy. Follow the directions on GitHub to set up that project as a remote for your local version of copy, push master, and you’re done!

提交回复
热议问题