0

My local repository is behind updates on the remote Git repository. I made updates on local without pulling the latest updates from remote first.

I did commit my updates on local, so if I'm going to force push my updates, would it overwrite the other guy's work? We are working mostly on same files.

I don't really understand why merged happens? I don't really know what's causing it, does anyone could help me and explain how this happen and how to avoid it? Cause if merge happens, contents of the files got repeated with something like

<<<<<<<update...
random
  • 9,774
  • 10
  • 66
  • 83
PHP Noob
  • 1,597
  • 3
  • 24
  • 34

2 Answers2

1

You should first pull in the changes to your local repo. Fix all the merge conflicts, then push the result back up to the repo.

What you are describing is a merge conflict. It happens when you and someone else changes the same line of code, git doesn't know which one to keep. So it places markers (>>>>,====, <<<<) so that you can manually edit the file and choose how to resolve the conflict. See this: http://githowto.com/resolving_conflicts

When working with git it's best to fetch or pull often. So when when you start to work on your project, do a pull, then work on your feature. When you are ready to commit do another pull, merge the conflicts if there are any, then push the code back up.

Here's a good git tutorial: http://gitimmersion.com/

ddevaz
  • 2,253
  • 1
  • 17
  • 10
1

Before you push it, you should pull it. When you pull from the remote server, merging will happen. There is no need to worry about it, because git will handle most of work for you, when you see <<<<<<, there will be a conflict, you can use:

git mergetool

see also this question, read every answer, I think it will help you:

How to resolve merge conflicts in Git?

Community
  • 1
  • 1
Bigxiang
  • 6,252
  • 3
  • 22
  • 20