Charlote22
Charlote22

Reputation: 1145

How to merge several repositories in git

I cloned several repositories (coding exercises) into one folder on my machine. Then I made a repository on github to keep that folder. But Git won't push my changes to the repository since they belong to other repositories. Please tell me how can I push all those repositories and my changes into one repo. Thanks

Upvotes: 0

Views: 46

Answers (2)

Philippe
Philippe

Reputation: 31137

You should indeed, like @Geru told you, delete the .git folder in the subdirectories if you don't want to keep the git history of the different directories you aggregate.

If you want to keep the history, you will have to have a look to the git subtree add -P <NameOfSubDirectory> <commit> command.

The goal here is for each source repositories, do in the target repository:

  1. Add a remote to the source repository
  2. git fetch
  3. git subtree add -P <NameOfSubDirectory> <commit> whith , the sha1 of the last commit you want to take

Upvotes: 1

Geru
Geru

Reputation: 654

You can simply remove the .git folder in every of those directories. After that git won't recognize them as directories already checked in to github.

Upvotes: 0

Related Questions