Skip to content

Instantly share code, notes, and snippets.

@psiborg
Created June 19, 2020 00:01
Show Gist options
  • Select an option

  • Save psiborg/56bf1db315b87b4e649280673410a225 to your computer and use it in GitHub Desktop.

Select an option

Save psiborg/56bf1db315b87b4e649280673410a225 to your computer and use it in GitHub Desktop.
Copy a Git repo to another repo

https://docs.microsoft.com/en-us/azure/devops/repos/git/import-git-repository?view=azure-devops#manually-import-a-repo

  1. Clone the source repo to a temporary folder on your computer using the bare option, and then navigate to the repo's folder.

Note: When cloning using the bare option, the folder name includes the .git suffix.

git clone --bare https://github.com/contoso/old-contoso-repo.git
cd old-contoso-repo.git
  1. Create a target repo, and make a note of the clone URL.

  2. Run the following command to copy the source repo to the target repo.

git push --mirror https://dev.azure.com/contoso-ltd/MyFirstProject/_git/new-contoso-repo

Warning: Using --mirror will overwrite all branches in the target repo which includes deleting any branches not in the source repo.

  1. If the source repository has LFS objects then fetch them, and copy them from the source repo to the target repo.
git lfs fetch origin --all
git lfs push --all https://dev.azure.com/contoso-ltd/MyFirstProject/_git/new-contoso-repo
  1. Delete the temporary folder.
cd ..
rm -rf old-contoso-repo.git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment