Copying/moving a Git repository including all branches to a new remote repository

Please note: this is written from the perspective of using the Git Bash shell.

  1. Clone the repository to be copied into a new location to ensure it is a fresh checkout
    git clone old-repo-url checkout-location
  2. cd into checkout-location, and run the following to checkout all branches from the remote:
    for remote in `git branch -r | grep -v HEAD`; do git checkout --track $remote; done
  3. If it doesn’t already exist, create the new remote repository e.g. new-repo
  4. Add a new remote that points to the new repository:
    git remote add new-repo new-repo-url
  5. Run the following to push all branches to the new remote:
    git push --all new-repo

Something to add?

This site uses Akismet to reduce spam. Learn how your comment data is processed.