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.

  • Git init initializes on different directory instead of the current
  • Git fetch and include all .gitignore files
  • Ruby - Parsing a string of a Hash using YAML - Error if hash entered raw and coerced to string rather than entered as string
  • Why am i getting “git status --porcelain failed”?
  • warning: Duplicated ref when git push
  • What is the difference between git status and git diff --name-only?
  • Configure Local Git Repo that Updates Two Different Remote Repositories
  • git merge ignores deleted files, existing on merged branch (renamed files)
  • 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.

    1. Move the repository: Simply login to the new server, cd to the parent directory where you now want to hold the repository, and use rsync to copy from the old server:

      new.server> rsync -a -v -e ssh .
    2. 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

    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 # character:

    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://<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

    $ git remote -v
    github (fetch)
    github (push)
    origin  git:// (fetch)
    origin  git:// (push)
    $ git remote set-url --push origin git://
    $ git remote -v
    github (fetch)
    github (push)
    origin  git:// (fetch)
    origin  git:// (push)

    Should be as simple as:

    git remote set-url origin git://

    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:

    #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:


    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
    Git Baby is a git and github fan, let's start git clone.