Creating a Full Copy of a Git Repository
Guest post from Peter Van de Voorde on creating a full copy of a Git repository. Learn more with his step by step guide.
A guest post by Peter Van de Voorde
I recently had to create a full copy of a GIT repository without the need for a link back to the old repository but with all branches, tags and the full history of the old repository.
And I wanted to share my way of doing this with anybody out there wanting to do the same.
Let’s call the original repository ORI and the new one NEW, here are the steps I took to copy everything from ORI to NEW:
Create a local repository using a git clone ORI <temp-dir> in the <temp-dir> directory
Go into the <temp-dir> directory.
Do git branch -a ,you’ll now see a list of the different branches in ORI
Use git checkout –track origin/branch-name to checkout all the branches you want to copy from ORI to NEW.
don’t checkout branches with -> in them, they are not real branches.
Now fetch all the tags from ORI using git fetch –tags
You can check your local tags using the git tag command and your local branches using the git branch -a command, do this before executing the next step.
Now clear the link to the ORI repository with the following command: git remote rm origin .
Now link your local repository to your newly created NEW repository using the following command:
git remote add origin <url to NEW repo>
Now push all your branches and tags with these commands:
git push origin –all to push your branches
git push –tags to push your tags
You now have a full copy from your ORI repo.
About Peter Van de Voorde
Peter is a 30-something Belgian with a passion about everything Agile. By day he’s an Atlassian Expert and ALM Consultant at RealDolmen. In the evening he’s a family man, an active member of Atlassian Answers and the Atlassian Belgian User Group, and a boardgame fanatic. To see Peter’s previous guest posts for Clearvision, see our guest posts tag. For more by Peter, visit his website: http://www.petervandevoorde.com/
Don’t stop your learning here! Check out Git 101, your free one stop guide to the basics of Git, including a Git cheat sheet to help you on your way!