Search code examples
git

Merging existing git repository with new one


I had a git repository hosted on GitHub. I recently switched machines and copied the files manually to the new machine rather than doing git pull, kind of forgot to do so. Now I made some changes and initiated a new git repository while adding the GitHub one as remote. I need to know how can I merge the two repositories i.e keep my commit history from the GitHub one and also keep my changes made to the new one? Thank you!


Solution

  • If there are not too many changes (just a single commit's worth), this is really easy:

    1. Clone the (original) repo from Github into a new folder. git clone ssh://... newfolder
    2. Copy and paste all your files from the folder where you made your changes, overwriting files in newfolder
    3. Make a commit in newfolder and push. At this point, your Github history is correct. Delete the old folder, name the new one whatever you'd like.