Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save DharmendraRathor/5d6c9902abfd1bfa1824a0b7766c5865 to your computer and use it in GitHub Desktop.
Save DharmendraRathor/5d6c9902abfd1bfa1824a0b7766c5865 to your computer and use it in GitHub Desktop.
Moving branches/tags from one git repository to another
A Moving branches/tags from one git repository to another
1. Clone existing git repo (source repository)
git clone --mirror <source git url>
eg
git clone --mirror [email protected]:source/source.git
2.
got to <folder with name of repo>
cd <folder with name of repo>
3. Add remote repository ( destination repository )
git remote add new-origin <destination git url>
eg
git clone --mirror [email protected]:destination/destination.git
4. Move all changes to destination repository
git push new-origin --mirror
B If you only want to move some branches
1. git clone <source git repository url>
2. checkout all branches to be moved to new git.
git checkout <branch>
3. verify branches to be moved using output of git branch command
git branch
4. add destination repository
git remote add new-origin [email protected]:destination/destination.git
5. move all local branches to destination repository
git push --all new-origin
6. move all tags to destination repository
git push --tags new-origin
C Move branch to new git repository and changing remote
after doing steps mentioned above to move branch from one git to another , use following command to set new
origin in git.
git remote rm origin
git remote rename new-origin origin
Note :
If you have already moved some branches and want to move one more branch from source git.
Running following command might override destination branche or give error.
It is always good to move all branches and tags to new repository and start using new repository.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment