Skip to content

Instantly share code, notes, and snippets.

@tkaczenko
Last active March 25, 2024 14:21
Show Gist options
  • Save tkaczenko/4cadd31516c827bd589f495c94364ac3 to your computer and use it in GitHub Desktop.
Save tkaczenko/4cadd31516c827bd589f495c94364ac3 to your computer and use it in GitHub Desktop.
How to merge changes from one repository to another one?

How to merge changes from one Git repository to another one?

For example, we need to migrate the Github (old) repository to Bitbucket (new) repository and we need to keep both of them for a while.

To do it we need to make the next steps

  1. Git clone Bitbucket (new) repository
 git clone git@bitbucket.org/example.git
  1. Add origin2 to Github (old) for the repository cloned from Bitbucket (new)
git remote add origin2 git@github.com/example.git
  1. Push develop-new Bitbucket (new) branch to Github (old)
git push origin2 develop-new:develop-new
  1. Clone Github (old) repository
git clone git@github.com/example.git
  1. Identify changes in Github (old), applied later than captured date
git log develop
git log develop-new
  1. Cherry-pick appropriate change-sets from develop into develop-new in GitHub
git switch develop-new
git cherry-pick ...
  1. Push appropriate changes in develop-saferent in GitHub
git push
  1. Fully clone and rewrite Bitbucket (new) repository by GitHub (old) repo, sample
git clone --bare git@github.com/example.git
git push --mirror git@bitbucket.org/example.git
  1. Remove the directory with the bare repository.
rm -rf example.git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment