How to migrate GIT repository from one server to a new one
I have a server that I’m taking down. The only thing I have left to migrate is my repository. This server is listed as the origin (master) for one of my projects. What is the proper way to move the repository to keep the history.
15 Solutions collect form web for “How to migrate GIT repository from one server to a new one”
To add the new repo location,
git remote add new_repo_name new_repo_url
Then push the content to the new location
git push new_repo_name master
Finally remove the old one
git remote rm origin
After that you can do what bdonlan said and edit the.git/config file to change the new_repo_name to origin. If you don’t remove the origin (original remote repository), you can simply just push changes to the new repo with
git push new_repo_name master
If you want to migrate all branches and tags you should use the following commands:
git clone --mirror [oldUrl]
to clone the old repo with all branches
cd the_repo git remote add remoteName newRepoUrl
to setup a new remote
git push -f --tags remoteName refs/heads/*:refs/heads/*
to push all refs under refs/heads (which is probably what you want)
Copy it over. It’s really that simple. 🙂
On the client side, just edit .git/config in the client’s local repo to point your remotes to the new URL as necessary.
This worked for me flawlessly.
git clone --mirror <URL to my OLD repo location> cd <New directory where your OLD repo was cloned> git remote set-url origin <URL to my NEW repo location> git push -f origin
I have to mention though that this creates a mirror of your current repo and then pushes that to the new location. Therefore, this can take some time for large repos or slow connections.
I’m just reposting what others have said, in a simple to follow list of instructions.
Move the repository: Simply login to the new server,
cdto the parent directory where you now want to hold the repository, and use
rsyncto copy from the old server:
new.server> rsync -a -v -e ssh firstname.lastname@example.org:path/to/repository.git .
Make clients point to the new repository: Now on each client using the repository, just remove the pointer to the old origin, and add one to the new one.
client> git remote rm origin client> git remote add origin email@example.com:path/to/repository.git
This is sort of done in parts in some of the other answers.
git clone --mirror git@oldserver:oldproject.git cd oldproject.git git remote add new git@newserver:newproject.git git push --mirror new
Take a look at this recipe on GitHub:
I tried a number of methods before discovering
git push --mirror.
Worked like a charm!
I followed the instructions on BitBucket to move a repo with all its branches there. Here come the steps with explanations following the
cd path/to/local/repo git remote remove origin # to get rid of the old setting, this was not in the BitBucket instructions git remote add origin ssh://firstname.lastname@example.org/<username>/<newrepo> # modify URL as needed git push -u origin --all # pushes _ALL_ branches in one go git push -u origin --tags # pushes _ALL_ tags in one go
Worked nicely for me.
You can use the following command :
git remote set-url --push origin new_repo_url
Example from http://gitref.org/remotes/
$ git remote -v github email@example.com:schacon/hw.git (fetch) github firstname.lastname@example.org:schacon/hw.git (push) origin git://github.com/github/git-reference.git (fetch) origin git://github.com/github/git-reference.git (push) $ git remote set-url --push origin git://github.com/pjhyett/hw.git $ git remote -v github email@example.com:schacon/hw.git (fetch) github firstname.lastname@example.org:schacon/hw.git (push) origin git://github.com/github/git-reference.git (fetch) origin git://github.com/pjhyett/hw.git (push)
Should be as simple as:
git remote set-url origin git://new.url.here
This way you keep the name
origin for your new repo – then push to the new repo the old one as detailed in the other answers. Supposing you work alone and you have a local repo you want to mirror with all your cruft in it, you might as well (from inside your local repo)
git push origin --mirror # origin points to your new repo
but see Is "git push –mirror" sufficient for backing up my repository? (in all don’t use
--mirror but once).
All the information (orgin, trunk, etc.) about the repository are stored in a folder named ‘.git’, where you are initializing the repository. So, you need to copy the contents to the new server, using the instructions provided Here
Please follow the steps:
- git remote add new-origin
- git push –all new-origin
- git push –tags new-origin
- git remote rm origin
- git remote rename new-origin origin
follow these instructions If you want to keep all the commits and branches from old to new repo
git clone --bare <old-repo-url> cd <old-repo-directory> git push --mirror <new-repo-url>
If you want to migrate a #git repository from one server to a new one you can do it like this:
git clone OLD_REPOSITORY_PATH cd OLD_REPOSITORY_DIR git remote add NEW_REPOSITORY_ALIAS NEW_REPOSITORY_PATH #check out all remote branches for remote in `git branch -r | grep -v master `; do git checkout --track $remote ; done git push --mirror NEW_REPOSITORY_PATH git push NEW_REPOSITORY_ALIAS --tags
All remote branches and tags from the old repository will be copied to the new repository.
Running this command alone:
git push NEW_REPOSITORY_ALIAS
would only copy a master branch (only tracking branches) to the new repository.
You can use git-copy to duplicate the repo with all histories.
git copy http://a.com/old.git http://a.com/new.git