Skip to main content
How to Move Code from One repository to Another without loosing history

It might seem like a nightmare for developers when they think about moving a Code Repository from One application to Another while preserving the history but indeed its the first step that is thinking about moving it is difficult, the rest is all the planned steps that one need to follow to move things around.

Let's take an example to understand the process where you need to move your repository from Github to Bitbucket. This process applies to all code repositories irrespective to the type as long as you have the Command Line on your local system to work with.


Here are the steps that you can take to move things around :

  • Take a clone of your current (Github) repository on your local system and move to the branch that you need to move first for instance 'master'.

git clone[repo-name].git

cd [repo-name]

git checkout master


  • Now, verify if you have taken the pull correctly and from the correct git repo using the command and validate as the "Origin" should be something like : "https://[email protected]/USERNAME/REPONAME.git (fetch)" and "https://[email protected]/USERNAME/REPONAME.git (push)"

git remote -v


  • Create a new repository where you want to move this repository i.,e create a new repository in Bitbucket for instance.


  • Edit the git config file for the repository using :

sudo vim .git/config


  • Change the URL (under remote "origin") and change "" to "". You may need to change the username if your username is different on Bitbucket. You should also change the repository URL as per the new repository created above i.e, [email protected]:USERNAME/REPONAME.git


  • Now, do a git push to the master branch, to push the master branch on this new repository with the history intact as :

git push origin master 


  • Done.



To Connect to Git using SSH Keys use the command as :

GIT_SSH_COMMAND='ssh -i ~/.ssh/ssh-private-key' git pull origin master


Published on

Blog type