clone a repo to another repo code example

Example 1: copy code from one repo to another git

# checkout repository A
git checkout [email protected]:username/repoA.git
# cd into old repository
cd repoA
# change remote origin to the newely created repo (exemple repoB)
git remote set-url origin [email protected]:username/repoB.git
# push branch into repoB
git push origin <branch>
# cd into new repository and pull branch
git checkout origin <branch>
# finally don't forget to reset origin for repoA
git remote set-url origin [email protected]:username/repoA.git

Example 2: clone from one repo to another

First clone the repository you want to work with. This step could be skipped if you want it all to happen in the folder you are already in.

git clone file:///path/to/repo/
Cloning will bring over the remotes specified in that directory. So you'll need to remove the remotes you don't want.

git remote rm <remote>
And add the ones you do, after you have created your remote repository.

git remote add origin <url>

Tags:

Misc Example