cdmh
cdmh

Reputation: 3344

Clone repository into GitHub

I have been using git locally for while a now and have a private repository with complete change history etc. I now want to share this on GitHub, so I need to clone from my local repo into a new GitHub repo. I cannot find any way to do this. How can I get all my history up onto GitHub?

Upvotes: 22

Views: 17618

Answers (4)

You can "reverse clone" your local repo (or remote, it doesn't matter) "old_repo" into a new, already created, github repo "new_repo", with all its branches and tags, like this:

  • First, create a local "bare clone" of your old_repo in an empty folder:
    • cd to this folder
    • git clone --bare "old_repo"
  • Now push it to your new_repo in mirror mode:
  • You can now delete the local folder with the bare clone if you want.

Source: https://docs.github.com/en/repositories/creating-and-managing-repositories/duplicating-a-repository

Upvotes: 1

Romain
Romain

Reputation: 12839

You simply want to create a new repository on your account on GitHub. Assuming your account name is CraigH, and you call you new repository NewRepo (imaginative, I know), you'd simply (assuming you have GitHub keys set up on your system properly):

  1. Add a remote to your local repository
  2. Push out your current history to GitHub
    • git push --set-upstream origin master

And from that point, your history in the master branch are in GitHub's master branch.

Upvotes: 6

Martin Green
Martin Green

Reputation: 1054

You do this by pushing to remote repo on GitHub. You should get the whole history and everything.

Upvotes: 0

Xion
Xion

Reputation: 22780

You don't need to "clone onto GitHub". You just have to create a repository on GitHub and push your changes there:

$ cd your_local_repo
$ git remote add origin [email protected]:USERNAME/REPO_NAME.git
$ git push origin master

Upvotes: 41

Related Questions