5

So I worked all day on a new feature in my project and after I finished it, I wanted to upload my local commits into the repository.

When I tried to push my commits to the git repository, that push was rejected because of some merge conflicts. So I went through the files, choosing "mine" or "theirs" for every conflict. After I was done with that, git didn't tell me anything about wether I had to do something more or not. Since I had resolved all conflicts I went on and tried to push again, ending up with the same conflicts I had to solve just before. (I could do that over and over again if I wanted to become insane)

I'm failing in trying to work properly with this tool for some months now.

Pull data. Work work. Commit work. Push. Eventually merge conflicts. Push again. Done. - This is how I had expected git to work but that seems not to be the case. So what steps am I missing? What do I have to do in order to not using up hours after hours reading tutorials like these that still don't solve my problems as they stop right after solving the conflicts?

Oh, and I am using git via PhpStorm 10.

Tekay37
  • 467
  • 5
  • 18

2 Answers2

6

Here is the sequence of work in your case,

git pull
# work work
git add $files
git commit
git pull --rebase
# if conflict resolve
git add $conflict_resolved_file
git rebase --continue
git push

So,

git pull --rebase

This above command is the most useful command in my git life which saved a lots of time.

Before pushing your newly commit to server, try this command and it will automatically sync latest server changes (with a fetch + merge) and will place your commit at the top in git log. No need to worry about manual pull/merge.

Find details at: http://gitolite.com/git-pull--rebase

Community
  • 1
  • 1
Sazzad Hissain Khan
  • 37,929
  • 33
  • 189
  • 256
0

The next time this happens, check PhpStorm's Event Log. You'll likely see a status message from git indicating that after resolving all of your merge conflicts, you need to manually commit the files that were affected during the conflict resolution. Only after doing that should you reattempt the push.

I don't recall if PhpStorm will suggest a commit message for you in this situation, but an appropriate one would be along the lines of "Merged branch 'X' into branch 'Y'"

Nate
  • 1,442
  • 14
  • 22
  • Yes, I saw that message. But comitting these files lead to "no changes detected" messages and pushing afterwards still lead to the same result. – Tekay37 Jan 13 '16 at 00:18
  • I wonder if this is a problem with the IDE (see http://stackoverflow.com/questions/22339334/phpstorm-git-not-changes-detected). What happens if you run `git status` on the command line after your conflict resolution is complete? Does it show the files you modified? – Nate Jan 13 '16 at 00:25
  • Yes, and `git status` tells me what to do (finally!). It said that my branch and origin/master had diverged. It said to use `git pull`. After that it said that my branch was 6 commits ahead of origin/master and said to use `git push`. Now everything seems to be up to date. On both sides. We'll see if there will be any more problems if I just do this extra `git pull`everytime before I `git push`. – Tekay37 Jan 13 '16 at 01:00
  • Despite having HEAD on the same checkout as master and origin/master, PhpStorm said with the next commit that git was in the detached head status. This program is really confusing to me. :( – Tekay37 Jan 13 '16 at 01:28