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.
- Clone the repository to be copied into a new location to ensure it is a fresh checkout
git clone old-repo-url checkout-location
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
- If it doesn’t already exist, create the new remote repository e.g.
new-repo
- Add a new remote that points to the new repository:
git remote add new-repo new-repo-url
- Run the following to push all branches to the new remote:
git push --all new-repo