Home > Software engineering >  When I try to do a git pull I see conflicts: Please enter a commit message to explain why this
When I try to do a git pull I see conflicts: Please enter a commit message to explain why this

Time:12-02

Could you please help me. I have some problems with git pull. When I try to do a git pull I see conflicts every time:

Merge branch 'prod' of https://github.com/frontend into prod
# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.

enter image description here enter image description here

But I have not conflicts in real. I merged dev branch into prod through GitHub PR. This problem is only on my computer, the git pull works correctly on other computers (without conflicts with the same branches). Committing the merge changes results in an extra commit.

Why might this be happening? How can I make sure that changes are pooled without conflicts and an extra commit does not appear?

I have tried updating all branches to the same state. But as soon as someone from the team pushes their changes into the branch, or merges the PR, then I cannot pull the changes, I have conflicts, although the branch has not changed. To avoid this problem, I have to delete the local branch every time and pull again from the origin.

For example, I delete the local branch git branch -D example-branch, then git fetch, and pull the branch from origin/example-branch. I have a local example-branch branch synced. I create a new branch example-new from exapmle-branch, make changes and commit. I create a PR from exapmle-new to exapmle-branch and merge it. I go to the local branch exapmle-branch, do a git pull and get a message with conflicts. I open a commit with conflicts and it's just the contents of my commit. There are no conflicts as such, the commit is simply duplicated and requires pushing it back. This happens every time. If I repeat this procedure on another computer, then this problem does not exist.

If I use git pull --rebase I receive the changes without additional commit and all is well. But I want to expect this behavior from a regular git pull. Because if I pick up the changes from origin on another machine, the extra commit won't show up. I want to solve this problem, not bypass it with another command.

Other computers do not have this behavior.

@quetzalcoatl, @AD7six, thank you very much for your answers! It's working! =)

git config pull.rebase true
git config --global pull.rebase true

CodePudding user response:

After re-reading your comments a few times, I think you want the --rebase to occur by default during pull, and currently it instead runs a --merge.

See AD7six's comment. He mentions git config. This is a command for configuring git client options.

With git config you can set the default behavior of many got commands, including both push and pull. After deciding whever you want git pull to do merge or rebase, check the docs, and use git config to set this mode as default.

see i.e. How to change global git settings to do git merge during pull
or way more in: How to make Git pull use rebase by default for all my repositories?

Just watch out what they were asking there for. Or of course, git docs, it's described there in detail as well.

It should be something like one of:

git config pull.rebase true
git config --global pull.rebase true

Config options are stored hierarchically in each working copy (locally cloned repo), and in your userprofile gitconfig file. Since you seem used to see one specific behavior, you would probably want to set this mode as global default for your userprofile on that machine. Otherwise you will have to set it again for each new cloned repo.

By the way:

If you run git config pull.rebase or git config --global pull.rebase without a new value to be set, it will instead readout the current setting and print it out. You may want to run this on your machine and other machines to see how the setting differs.

  • Related