gitvisual-studio-codevscode-git

Make vscode's git integration cancel push if behind remote (instead of automerging)?


I have been using Atom's git integration for a long time. Now that it's gone obsolete, I switched to vscode, whose git integration is if not terrible in comparison, at least different.

One of the differences is that when I'm behind the remote and want to push, when Atom's git integration realizes it's behind, it aborts and just does a fetch (not even a merge), informing me of it and letting me decide what to do. VSCode instead does a merge without asking me anything, and even pushes all that to the remote without any kind of confirmation from me.

Is there a way to disable this and do it atom-style ?


Solution

  • The only VSCode operation which would do "an automatic merge followed by an automatic puSH when I only asked for a simple push" is the sync option, which, as explained here, does a pull (fetch + merge), followed by a pull.

    sync

    Make sure your Git post-commit command is not set to sync or push, or you would experience a pull and/or push after each commit!

    You can still do a push only through the three-dot menu, as explained in "How to commit and push your changes to your GitHub repository in VScode" from ZeroesAndOnes:

    https://miro.medium.com/v2/resize:fit:1100/format:webp/1*fEymXmfqPwsolwGuGFvMIQ.png


    Note (Q4 2024), the issue you created (microsoft/vscode issue 174198) also mentions, from Alex Recuenco, an alternative based on Git settings:

    If you want to make sure that pulling doesn't do a merge commit

    pull.ff=only
    
    git config pull.ff only
    # I recommend adding it globally
    git config --global pull.ff only
    

    Which should be the default by the principle of "least surprise". But probably Git is not very keen on changing defaults

    Once you put that setting in your Git config, if you use the "Sync" feature, it won't create a merge.

    Instead a pop up with an error will appear saying:

    git pull --tags origin renovate/configure
    From ssh://github.com/myuser/myrepo
    * branch            renovate/configure -> FETCH_HEAD
    hint: Diverging branches can't be fast-forwarded, you need to either:
    hint:
    hint:     git merge --no-ff
    hint:
    hint: or:
    hint:
    hint:     git rebase
    hint:
    hint: Disable this message with "git config advice.diverging false"
    fatal: Not possible to fast-forward, aborting.