Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I always have to merge manually on git pull?

Tags:

git

git-merge

I am a new user of git and can't figure out how to get around this. I have had some experience with SVN and am going by SVN behavior.

Any time I pull files from remote repository, and the file I have modified are also modified remotely, it needs merging. I can understand merge conflicts for complex changes, but I am seeing merge conflicts for very small (e.g. one line change in different functions) changes. As far as I remember, SVN could merge most of it automatically and will put the file in conflicted state only if automatic merge failed.

For git, it seems to be happening every time and forcing to open the git merge tool. Is there any way to automatically merge the files? Am I missing some setting that is basically putting the repository in conflicted set by default?

like image 528
user871199 Avatar asked Jul 31 '11 02:07

user871199


People also ask

Does git pull always create a merge commit?

By default, the git pull command performs a merge, but you can force it to integrate the remote branch with a rebase by passing it the --rebase option.

Why does git merge when I pull?

This usually happens when we're collaborating on a branch with other people, and we've made changes on our local version of a branch, and someone else (or the other you, if you use git to sync between multiple dev platforms) has made changes to the remote version of a branch in the meantime.

What does can't automatically merge mean?

That means that your pull request can't be merged into the upstream without the upstream owner(s) having to resolve merge conflicts.


1 Answers

A common cause of this is differing line endings. Are you sharing a repo with someone else using a different OS? SVN does some munging of line endings. Git, on the other hand, stores files byte-for-byte exactly as they are by default. That means that when a Windows user saves a file with \r\n line endings and a Linux user saves the file with \n line feeds, every line appears changed, and if any other changes are in play, it causes conflicts everywhere. To change the way line endings are handled, use the configuration setting "core.autocrlf". In a repo where different OS's are in play, I recommend setting it to "input" for Linux users and "true" for Windows users:

git config [--global] core.autocrlf input

or

git config [--global] core.autocrlf true

Actually, I'd say just use these settings globally all the time. They'll save you some heartache. Read more about core.autocrlf on the git-config man page, and note that if you're suffering from this problem and you turn autocrlf on with an existing repository, you may see some startling behavior, but it can be explained.

like image 196
Ryan Stewart Avatar answered Nov 13 '22 01:11

Ryan Stewart