Tuesday, March 11, 2014

Migrating your Git Repos to new Git Platforms or a new Remote "Origin"

This article is relevant for: 
- Git version
it may or may not work for other versions.

We recently moved our local GIT repos hosted on a custom install of GitLab in a local server to GitLab cloud.

Our existing repos had full history to them so they had multiple branches, commit histories, tags etc.

Although moving your repos to new remotes or a new "origin" is not a very hard thing, it can be a bit tricky as there are a few steps you need to follow.

Here are the steps I followed which seemed to work perfect.

// Add a new "temp" remote repo to your existing GIT repo
$ cd existing_git_repo
$ git remote add newRemote git@gitlab.com:apps/my-app.git
$ git push -u newRemote master

// Note: this might be needed if you are using https or have a very large code base
// for the error - fatal: The remote end hung up unexpectedly
// the solution is the run the below command on the client to increase the postBuffer size before trying to re-run the git push. Use the below command to set the postBuffer size to 100MB.

$ git config http.postBuffer 104857600

// Now swap the "origin" repo to the new location of "origin"
$ git remote -v // to show all remote repos and see your remotes
$ git remote rm origin
$ git remote add origin git@gitlab.com:apps/my-app.git
$ git config master.remote origin // not sure if this is needed (or why its needed, but was suggested in a tip I came across online)
$ git config master.merge refs/heads/master // as above

// Now, delete you temp remote repo
$ git remote rm newRemote

// Finally, Push all your tags
$ git push --tags

// and also move all your tracked branches
$ git push --all -u

That's it :)

Hope this helps someone, I know I'll be coming back here in the future to go over this again.

No comments:

Post a Comment

Fork me on GitHub