1

I am trying to move one of my SVN repositories to a new repository in GitHub.

Since I don't have much experience yet with Git, I'm trying to follow instructions I found on Stack Overflow and GitHub.

  • I only need the trunk of the project, which is in a repository together with several other projects.
  • I want to keep my history
  • I am not planning to go back to SVN soon

I executed the following commands. What am I missing/doing wrong here?

git svn init https://svn.my-domain.org/svn/MyRepository/MyProject/trunk/
git svn fetch
git remote add origin git@github.com:MyUserName/myrepository.git
git config branch.master.remote origin
git config branch.master.merge refs/heads/master
git push

The last command gives me the following error:

To git@github.com:MyUserName/myrepository.git

 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'git@github.com:MyUserName/myrepository.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

I understand that I must merge my GitHub repository (witch has only the readme file) with the local Git repository with the files/history from SVN.

I tried in different ways the git push, but that didn't succeed. How should can I execute the push?

Thanks in advance

Schiavini
  • 2,869
  • 2
  • 23
  • 49
  • Your Git repo (on GitHub) currently has a README which doesn't yet exist in your local repo, so when you try to push your changes, the remote repo is rejecting them. As the hint suggests, try doing a `git pull` to integrate the remote files, followed by `git push`. – Graham Oct 27 '13 at 17:07
  • Bitbucket has a good step by step [Migration Guide for Subversion to Git on Bitbucket](https://go-dvcs.atlassian.com/display/aod/Migrating+from+Subversion+to+Git+on+Bitbucket) You could just reuse for Github – Michael Ver Oct 27 '13 at 17:35
  • @Graham, I tried the git push but that didn't work with the repository. However I just tried with another repository and it did work. No idea what was the difference! Thanks anyway – Schiavini Oct 28 '13 at 09:06
  • @MichaelVer, I'll use that if I need it again, thanks – Schiavini Oct 28 '13 at 09:06

1 Answers1

2

If you don't care about GitHub initialization file (.gitignore or README.md), you can:

git push --force

If you do a git pull, that will add to your current commit one from GitHub with its content.
Then a git pull would work.

Don't forget that you can create on GitHub a completely empty repo, which means you can then push whatever history you want.
Simply unselect the "Initialize this repository with a README" option

https://github-images.s3.amazonaws.com/help/repo-create-name.png

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250