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?
Asked
Active
Viewed 1.6k times
3 Answers
40
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 git@github.com:USERNAME/REPO_NAME.git
$ git push origin master

Xion
- 22,400
- 10
- 55
- 79
-
Thanks - and that will keep my commit history? – cdmh Apr 27 '12 at 07:53
-
Yes, everything from your local repo's master branch will be pushed to GitHub one. If you got some tags, you would also want to push them via `git push --tags`. – Xion Apr 27 '12 at 07:54
-
2I would add that for the first push, `--mirror` with `-u` might be a sensible thing to use: `git push --mirror -u origin` – kostix Apr 27 '12 at 08:20
-
"Official" article on the subject: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line – Nikos Alexandris Jun 05 '14 at 14:13
-
It's my understanding that `clone` copies all the branches in a repository, not just the `master` branch. If that's true, then it seems like following the instructions in the answer will have a different effect than running `clone` from the remote location. Is there a way to modify the instructions so they have more nearly the same effect as running `clone` from the remote location? – Vectornaut Jun 09 '16 at 04:55
6
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):
- Add a remote to your local repository
git remote add origin git@github.com:CraigH/NewRepo.git
- 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.

Romain
- 12,679
- 3
- 41
- 54
0
You do this by pushing to remote repo on GitHub. You should get the whole history and everything.

Martin Green
- 1,056
- 8
- 15