0

I was working on a project by myself and got the merge conflict error. Here's what happened.

  • First, I created a repository for the project
  • I've been updating the repo alone without any collaborators
  • I've been updating the changes by git add . -> git commit -> git push origin master.
  • There's only one branch, master. (origin/master.) The project exists only in the repository and my machine.

Few days ago, I tried to do my usual update but encountered a merge conflict error. I think it is because I've added readme.md and other stuff to the repository (in github) and committed some changes locally but not pushing it to the repo. Still not clear why it happened though.

What I want to do is, the code in the machine (local changes) is up to date. I don't care about the changes occurred in the repo because it's outdated. Just want to update the repository with the changes committed locally.

I was researching about this and it seems like git rebase or git pull --rebase are the possible options. In this case, which one will be more suitable for me? Are those even the right for me?

Thank you

WasabiTea
  • 389
  • 2
  • 10
  • If you just want to update the repository with what you have locally, and are ready to lose the changes made on the server, but not locally, what you need to do is to push, not pull. `git push --force`. I've warned you. I hope you read this comment carefully. – JB Nizet Jul 09 '18 at 21:39
  • @JBNizet Thank you for the reply. Yea the changes made in the server are minor and okay to lose. I think I can use the `git push --force`. But I also want to know what I should do when I need to keep the changes made in the server, and update my local changes when there's a merge conflict. Not exactly necessary for my case, but would be really useful to know. – WasabiTea Jul 09 '18 at 21:56
  • I would git fetch, then git rebase -i upstream/master. But most importantly, I wouldn't use github to make changes directly on the server, and I wouldn't work on master directly, but instead work in branches. – JB Nizet Jul 09 '18 at 21:59

2 Answers2

0

You need to do a

git fetch

first as you have updated the readme.me remotely. once you fetch the remote change, your git status will show that your branch has diverged. In order to resolve that, you do a

git rebase

this command will run your current local commit on top of changes on remote- without creating a merge commit. Now if you look at git status again, you will see your branch (local) is X commits ahead of remote. At this stage, you can do a git push to remote master i.e origin/master, or any other branch for that sake. Hope this helps.

If you don't care about remote changes at all and would like to overwrite remote changes, do a

git push -f

priteshbaviskar
  • 2,139
  • 2
  • 20
  • 27
0

In your case you need to bring your local branch up-to-date with remote repo branch. You should use git pull --rebase to do so, as it applies your local changes on top of remote changes. Check this SO answer explaining the difference between git pull --rebase and git rebase

Aditya Singh
  • 15,810
  • 15
  • 45
  • 67