1

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'.

Chitranjan
  • 47
  • 8
  • 2
    1. Clone the repos locally, 2) Manually move the files from the "wrong" repo to the "right place". 3) Update your repos (commit changes). 4) Push your updates back to GitHub. – paulsm4 Nov 02 '20 at 04:11
  • Are there also, some set of git commands which can help in doing so.? – Chitranjan Nov 03 '20 at 08:01
  • Yes: [clone](https://git-scm.com/docs/git-clone), [mv](https://git-scm.com/docs/git-mv), [add](https://git-scm.com/docs/git-add), [commit](https://git-scm.com/docs/git-commit) and [push](https://git-scm.com/docs/git-push) – paulsm4 Nov 03 '20 at 15:53

1 Answers1

1
  1. 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).

  2. 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>
    
  3. Fetch the Repo-2 remote changes

    git fetch Repo-2
    
  4. 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
    
  5. 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).

  6. If all the changes look good just commit them:

    git commit --message "Add folder-xyz from Repo-2/main"
    
Marcin Kłopotek
  • 5,271
  • 4
  • 31
  • 51