Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I merge an existing git repository into an empty one and preserve the history?

I have a project that I've been working on called "system" that I set up as a repo. I've been pulling and pushing to the project (system.git).

Now I want to publish it to a site like github. What is the best way to take my current project and push it into the new github project without losing my history?

Thanks!

like image 884
Dooltaz Avatar asked Aug 25 '09 18:08

Dooltaz


2 Answers

Create the repo on Github.

Then you will set the origin to that project

git remote add origin [git hub url]

Then do a:

git push origin [branch name]

And you will push your local repository to Github (with all history etc)

like image 191
Gavin H Avatar answered Sep 23 '22 00:09

Gavin H


This is really a reply to hacker's comment on the answer from ghills, but it got a bit long, and SO didn't like me putting a bunch of code in a comment.

...or you could use a name other than "origin". For instance, I have a repository in which my "master" branch pushes to one github repo, and the "hacking" branch pushes to another.

In .git/config, I have this:

[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = [email protected]:xiongchiamiov/fourU.git
[branch "hacking"]
    remote = origin
    merge = refs/heads/hacking
[remote "main"]
    url = [email protected]:xyztextbooks/fourU.git
    fetch = +refs/heads/*:refs/remotes/main/*
[branch "master"]
    remote = main
    merge = refs/heads/master
like image 22
Xiong Chiamiov Avatar answered Sep 27 '22 00:09

Xiong Chiamiov