gitvisual-studioazure-devopsteam-explorergit-workflow

How to Avoid Needless Merges with Visual Studio Git


Currently our workflow requires when we want to commit to the local branch, we must first fetch and pull from the remote branch so that our local branch is updated. Then we are able to do a commit on local and then push to remote. If we commit to local branch first, and then pull updates from remote branch, Visual Studio will automatically commit a merge for us, regardless if there are conflicting changes or not. We want to avoid unneeded merges.

So my question is, is there an option, or action, that can perform this automatically in VS? One action you click and will first pull from remote, update local, then commit, then push back to remote? Right now we are doing all three actions manually to avoid VS generating unnecessary merge commits.

VS has an option "Commit and Sync All", the purpose of which seems like it'd be intended for what we are trying to do, but it doesn't. It just commits first, then does a pull and a push, which still generates needless merges.


Solution

  • While VS 2017 does not have the ability to directly pass the --rebase flag to the pull command, it will honor the config setting to rebase instead of merge during pull. You can set this via the command line, or in "Team Explorer->Git Settings" either globally or for the current repository. The checkbox is labeled "Rebase local branch when pulling".

    Hope this helps.