3

My remote colleague always creates dummy merge commits with no practical reason - they contain the very same code which was already pushed to the repo since he last time pulled. I want to prevent that but can't really figure out how he does it - he says that the only thing he does is git pull origin master and for some reason it pulls down remote code as his own. Any ideas how that could be happening? I think I'll go and tmate to his terminal to check myself.

scythargon
  • 3,363
  • 3
  • 32
  • 62
  • 5
    Does this answer your question? [How to avoid merge commits from Git pull when pushing to remote](https://stackoverflow.com/questions/30052104/how-to-avoid-merge-commits-from-git-pull-when-pushing-to-remote) – Andris Dec 03 '19 at 09:12

2 Answers2

5

The default behavior of git pull is to merge.

Incorporates changes from a remote repository into the current branch. In its default mode, git pull is shorthand for git fetch followed by git merge FETCH_HEAD.

https://git-scm.com/docs/git-pull

To change that you can add --rebase (git pull --rebase), or simply configure git to always rebase if that's your desired default behavior.

Add the following to your .gitconfig.

[pull] 
  rebase = true

Or configure it from command-line:

git config --global pull.rebase true
zrrbite
  • 1,180
  • 10
  • 22
3

The local branch has one or more commits which haven't been pushed and merged to the branch in the remote repository, and at the same time the branch in the remote repository has one or more commits which haven't been fetched and merged to the local branch. The 2 branches are diverged.

To prevent merge commits from being created, add --rebase or -r to git pull, git pull origin -r master for example. This way, the branch in the remote repository will be fetched first and then the new commits on the local branch are rebased onto the fetched head. The local branch will always be up-to-date with or ahead of the branch in the remote repository.

ElpieKay
  • 27,194
  • 6
  • 32
  • 53