7

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!

Dooltaz
  • 2,413
  • 1
  • 17
  • 16

3 Answers3

11

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)

Gavin H
  • 10,274
  • 3
  • 35
  • 42
  • 1
    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 Aug 25 '09 at 19:04
  • 1
    You could've actually force push it by `git push [git hub url] +refs/heads/*:refs/heads/*` – Michael Krelin - hacker Aug 25 '09 at 19:08
  • Or "git push origin --all --tags" to push all branches and tags. – Jakub Narębski Aug 27 '09 at 10:01
2

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 = git@github.com:xiongchiamiov/fourU.git
[branch "hacking"]
    remote = origin
    merge = refs/heads/hacking
[remote "main"]
    url = git@github.com:xyztextbooks/fourU.git
    fetch = +refs/heads/*:refs/remotes/main/*
[branch "master"]
    remote = main
    merge = refs/heads/master
Xiong Chiamiov
  • 13,076
  • 9
  • 63
  • 101
0

This is also useful for managing tracking of remote branches.

Peter Krenn
  • 397
  • 2
  • 5