views:

224

answers:

3

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!

+4  A: 

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)

ghills
Thanks for the start ghills. I had to do a "git remote rm origin" first, then I could change it. I then had to do a "git pull origin master" to merge the master branch. Then I could do the "git push origin master". Awesome! Again, thanks!
Dooltaz
You could've actually force push it by `git push [git hub url] +refs/heads/*:refs/heads/*`
Michael Krelin - hacker
Or "git push origin --all --tags" to push all branches and tags.
Jakub Narębski
+1  A: 

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
Xiong Chiamiov
A: 

This is also useful for managing tracking of remote branches.

Peter Krenn