Moving codebase from one git repository to other
Ever since github opened private repository feature to general user, all the developers have been moving their project repo to github. I myself too jumped on the bandwagon recently, and started putting up old projects as well as unfinished ones(there's a lot of those) as private repos in github. I had been taking shelter under gitlab and bitbucket as a backup place for them, but decided it was time to move them to github once and for all.
Steps :
1. First I pulled the projects off of the old repo, using the following line :
git clone <git-project-url from old repo>
2. After getting inside the project directory, I used the following command to point it to my newly created repo in github.
git remote set-url origin <git-project-url from github>
3. I entered the following to confirm the change worked.
git remote -v
Now, if you didn't have a README.md file on the previous repo, but github created one for you when you created the repo, this is going to create a problem because, this README.md file was never part of the git history in the old repo, and github cannot do a merge because it sees it as a unrelated history. In fact, you will even get a "fatal: refusing to merge unrelated histories" when you try to do a git pull.
4. To solve this issue, you need to force merge the new changes onto the old git commit history with the following command.
git pull --allow-unrelated-histories
5. Finally, push your project to your new repo using git push.
Comments
Post a Comment