Nootuff
Nootuff

Reputation: 49

Merge local and remote git repositories containing different files

So I've made the mistake of pushing a project stored in a local repository on my laptop to GitHub and then made some modifications directly to the files in the remote repository on the website itself. Now I can't pull the files from GitHub and I can't push any changes made in the local repository to the remote because both repos have slightly different files. Is there any way I can merge these two repositories so I can keep on pushing changes from the local to the remote?

Upvotes: 1

Views: 1386

Answers (2)

lopho
lopho

Reputation: 177

  1. commit any changes in your local branch (or reset them if not required)
  2. fetch from GitHub to your local repository
  3. merge the fetched branch (e.g. origin/master) into your local branch
  4. resolve any conflicts during merge locally
  5. push your local branch to GitHub

Upvotes: 1

SwissCodeMen
SwissCodeMen

Reputation: 4895

I think your problem is, that you have local files, were are changed and are staying in the working directory. So first step, just must commit your local changes by using the

git commit

command. Now you have a empty working directory and now you can pull from the remote repo by using the

git pull

command. This will fetches a new changes and merge them to your local changes. Only there is no conflicts (changes in the same file in local and remote version). If there are no conflicts, you can push your changes to remote repo, otherwise you need to resolve all conflicts and then you can also push the changes to the remote repo.

After pushing you will have on both (local and remote) the same version.

Upvotes: 2

Related Questions