Getting into rebase -> merge cycle with Git

I have a branch mainline tracking remote branch origin/mainline

My local branch went out of sync with the remote branch so I did a git pull and now when i do a git status I get:

  • Can't push to git bare repository on windows
  • Git Push Questions - Pedantic
  • Git list of staged files
  • Git - info on tracking branch
  • Make git-grep ignore large text files
  • Error after commit on git repository Android application
  • Your branch is ahead of 'origin/mainline' by 2 commits.
    

    Now i want to squansh these into a single commit so i ran

    git rebase -i HEAD~2
    

    It opens up the file where I can squash the commit and pick one to use. I was expecting it to show just 2 commits (my original top level commit + the merge after pull ) but it has 3 commits in them with no merge commit. If i go ahead and sqash these into single one Git complains that I have a conflict, ( the same conflict i had after a pull).

    If i resolve the conflict and run git rebase –continue it end up in the state where I have 2 commits!! Please help me resolve this, im stck here for almost a day !!

  • Change node pm2 git remote url for deployed project
  • How do I measure the number of commits before a push from a Git repository?
  • Go back in history to an undamaged version?
  • Get a blob from a commit?
  • zsh tilde (~) expands differently on OS X
  • After using git to locally track a project, how can I add it to GitHub?
  • One Solution collect form web for “Getting into rebase -> merge cycle with Git”

    Rebase doesn’t normally preserve merges, you have to pass the -p or --preserve-merges flag to get it to do that.

    However, your process for synchronizing with the remote is incorrect, and might lead you to rewriting commits that have already been pushed and shared with other people, which can lead to a lot of problems with synchronization and conflicts.

    If you wanted to do a squash, then instead of doing a pull and a merge, you should have fetched and rebased instead:

    git fetch origin
    git rebase origin/mainline mainline
    git rebase -i mainline~2
    

    You can combine the last two commands if you want, but doing them separately has the advantage that you can then verify that you didn’t mess anything up with the squash by doing git diff mainline@{1} afterwards.

    So, to get out of your current situation, you could do a hard reset back to mainline^, or whichever commit you were at before you tried to do the merge/pull, then run the rebase commands above.

    Git Baby is a git and github fan, let's start git clone.