-2

Could you please help me. I have some problems with git pull. When I try to do a git pull I see new commit 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

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.

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

It helps me:

git config pull.ff true
git config --global pull.ff true
Gleb
  • 9
  • 2
  • 6
    The message you have displayed has nothing to do with conflicts. There are no conflicts. Why do you say there are conflicts? – matt Dec 01 '22 at 16:29
  • 3
    As matt said, there are no conflicts here. This is the normal result of a normal merge. Since `git pull` runs `git merge`, this is all quite normal. – torek Dec 01 '22 at 22:41
  • Why normal? Other computers do not have this behavior. – Gleb Dec 02 '22 at 08:53
  • 1
    See also [When should I use git pull --rebase?](https://stackoverflow.com/questions/2472254/when-should-i-use-git-pull-rebase) - git config affects the behavior of `git pull` with no args. – AD7six Dec 02 '22 at 09:02
  • Thanks for answers. I try use `git pull --rebase` and I received the changes without an extra commit. But I want to expect this behavior from `git pull`. Because if I pick up changes from `origin` on another computer, then the additional `commit` does not appear. I want to solve this problem, not bypass it with another command. – Gleb Dec 02 '22 at 09:33
  • `Still, the question remains.` if you still have a question - don't accept an answer :). `Why does merge not work correctly?` it's not apparent what you are expecting, and there isn't enough details in the question to figure that out either. Showing your git config, and doing _the same_ merge on two different working copies with the different results would maybe clarify. Also [Please do not upload images of code/data/errors.](//meta.stackoverflow.com/q/285551) – AD7six Dec 02 '22 at 11:02
  • In any event please edit the question to focus on the problem as best you can matching your current understanding - e.g. you hopefully now know there are no conflicts, yet the question still asks about conflicts. – AD7six Dec 02 '22 at 11:04

1 Answers1

1

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.

quetzalcoatl
  • 32,194
  • 8
  • 68
  • 107
  • Still, the question remains. With this action, we switched to `rebase`, but this is not quite the same. Why does `merge` not work correctly? On my second working computer under WinOS, `git pull --merge` works correctly without an additional commit. An additional commit appears on a MacOS computer. We were able to get away with `git pull --rebase`, but this did not solve the `merge` problem =( – Gleb Dec 02 '22 at 10:45
  • @Gleb `merge` ***should*** add a new commit that joins your changes and remote changes. There is a special kind of merge, called fast-forward (in short: `ff`), it may occur ***only*** when in very specific case. [This site explains it quite well](https://www.atlassian.com/git/tutorials/using-branches/git-merge). If it occurs, such `merge` will not ask for 'message' nor create a commit. However, FF is not always possible, and then git will create commit and ask for message as usual. There is `git merge --no-ff` so maybe there are `git config` switches that can default o no-FF, maybe you had it? – quetzalcoatl Dec 02 '22 at 23:17
  • 1
    My config did not contain `ff`. I just added it and now it seems to work correctly. Thank you very much, it answered my question =) Strange, but on another computer there was also no `ff` config, but it worked there initially. Now I will know it. Thanks guys again for your help! – Gleb Dec 03 '22 at 00:26