How to avoid merge commits from Git pull when pushing to remote

I have a repository and some local changes to commit. Before committing, I pulled the changes onto my local using Egit in Eclipse.

It creates a merge commit and I submit my commit over it.

Now when I am trying to push to origin, it is showing that it will push my commit as well as merge commit. But ideally, merge commit should not be a part of remote repository.

How to avoid this?


Use rebase option whenever you pull from remote repository. Please follow the below steps,

  • Commit your changes - It will create a new commit in your local.
  • Now do git pull --rebase <remote-name> <branch-name> .
  • Basically the rebase take out your commits that you committed on the current branch HEAD as a patch. Then it will apply all the remote commits on top of HEAD and then applies your commits on top of it.
  • So best practice is to commit changes then pull remote commits by using rebase option.

  • The usual strategy is to work on a branch. When the remote master changes, pull the changes to master and instead of merging, rebase the branch.

    See Git Rebase at Atlassian.


    当你有未提交的变更时,你可以这样做,

    git stash
    git pull --rebase <remote> <branch>
    git stash pop
    
    链接地址: http://www.djcxy.com/p/48950.html

    上一篇: 在git中合并的rebase有什么优点?

    下一篇: 如何避免合并从Git pull提交到远程时提交