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

前端 未结 4 1136
抹茶落季
抹茶落季 2021-01-30 13:06

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

相关标签:
4条回答
  • 2021-01-30 13:41

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

    1. Commit your changes - It will create a new commit in your local.
    2. Now do git pull --rebase <remote-name> <branch-name>.
    3. 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.
    4. So best practice is to commit changes then pull remote commits by using rebase option.
    0 讨论(0)
  • 2021-01-30 13:46

    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.

    0 讨论(0)
  • 2021-01-30 13:58

    When you have uncommitted changes, you can do,

    git stash
    git pull --rebase <remote> <branch>
    git stash pop
    
    0 讨论(0)
  • 2021-01-30 14:00

    You can run

    git config --global branch.autosetuprebase always
    

    to make git pull --rebase the default behaviour for git pull.

    0 讨论(0)
提交回复
热议问题