Home > Software engineering >  How to copy my private repo to a new public repo and retain branches and commits?
How to copy my private repo to a new public repo and retain branches and commits?

Time:12-28

I have a private repo on Github that I used for a small take-home project for an interview with a company. There were 2 engineers who were watching my repo but I didn't finish the project. I want to keep working on it and add more features / scale it up in a separate public repo.

I know I cannot fork my current private repo, but I would like to copy it to a new one and maintain the branches and commits I made. I also want to remove any ties between the old and new repo so that any commits I make to the new repo will not be reflected in the old repo.

Does anyone know what git commands I should use?

I was looking into Duplicating a Repository but I wasn't sure if doing a bare clone for the repo will separate the 2 repos so that any new commits will be only made to the new repo.

CodePudding user response:

First, you will need to

git clone

your old repo. Now let's download all branches:

git pull --all

Now, let's add a new remote, like

git remote add newremote [email protected]:portfolio/space.space_name.git

See more here: https://articles.assembla.com/en/articles/1136998-how-to-add-a-new-remote-to-your-git-repo

Now, let's push all

git push --all newrepo

CodePudding user response:

Using the git --mirror method:

  1. clone the old private repo

  2. create a new public repo on github

  3. Create a new remote for the public repository on your local machine, like this:

    git remote add public https://github.com/benevolentBanana135/new-public-repo.git

  4. Push all branches and commits from your private repository to the public repository (that's where the magic happens):

    git push --mirror public

comment:

git push --mirror pushes all branches, commits, tags, and commit history from the local repository to the remote repository, while git push --all pushes all unpushed branches from the local repository to the remote repository, but does not include tags or commit history.

  •  Tags:  
  • git
  • Related