Humza Khan
Humza Khan

Reputation: 733

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!

Upvotes: 1

Views: 902

Answers (3)

Arjun Vinod
Arjun Vinod

Reputation: 11

Since you have already set remote url you can either create a new branch to store the changes and push it.Later you can merge the branches when necessary. Or Since you have created local repository and set remot-url you can directly push to your repository after commiting. Hope this helps.

Upvotes: 1

mkasberg
mkasberg

Reputation: 17262

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.

Upvotes: 1

r3mus n0x
r3mus n0x

Reputation: 6144

You just need to rebase your new branch with upstream branch. You can do this by setting an upstream branch for your new branch with git branch -u origin/my_branch (assuming the remote you added is called origin and you are currently on your new branch) then execute git pull --rebase to rebase your branch. After that you can git push your new commits on top of your existing commits on GitHub.

Upvotes: 2

Related Questions