Reputation: 67
I mistakenly created the second repo(Repo-2). I can easily delete this and again add the files in the existing repo(Repo-1). But I want to know if I can transfer the folder(folder-xyz) from Repo-2 to Repo-1
Also, if it matters, Default branch for Repo-1 is 'master' and for Repo-2 is 'main'.
Upvotes: 1
Views: 1222
Reputation: 5981
Open CLI in the directory with your local copy of the repository you want to transfer the folder-xyz directory to (Repo-1 in our case).
Add additional remote pointing to the repository you want to transfer the folder-xyz directory from (Repo-2 in our case):
git remote add Repo-2 <Repo-2-remote-reposiotry-url>
Fetch the Repo-2 remote changes
git fetch Repo-2
Checkout only the changes related to the folder-xyz directory we want to transfer from Repo-2 main
to the local Repo-1 master
branch:
git checkout Repo-2/main -- folder-xyz
Examine the status to see if you did what was intended:
git status --branch --short
Now you should see all the files from folder-xyz added to git index (staging area).
If all the changes look good just commit them:
git commit --message "Add folder-xyz from Repo-2/main"
Upvotes: 2