Why do I always have to merge manually on git pull?
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?
2 Solutions collect form web for “Why do I always have to merge manually on git pull?”
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.
From the manual:
https://book.git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging
git commit -a
At this point the two branches have diverged, with different changes
made in each. To merge the changes made in experimental into master,
rungit merge experimental
If the changes don’t conflict, you’re done. If there are conflicts,
markers will be left in the problematic files showing the conflict;git diff
will show this. Once you’ve edited the files to resolve the conflicts,
git commit -a
will commit the result of the merge. Finally,
gitk
will show a nice graphical representation of the resulting history.
Q: What Git client are you using? The Git command line tool? Or something else?
Q: Also, are the files in question both Linux, or both Windows? Or are they from different environments?