gitansibledevops

How to use Ansible git module pull a branch with local changes?


My git workspace is dirty, there are some local modifications. When I use command git pull origin master it works fine because there is no conflict.

But when I'm trying to use Ansible like git: repo=xxxx dest=xxx version={{branch}} I got error:

Local modifications exist in repository (force=no)

If I add force=yes, then I will lose my local modifications.

What can I do to keep my local changes and pull latest commit from git by using Ansible git module.


Solution

  • You cannot achieve it using the git module.

    Ansible checks the result of:

    git status --porcelain
    

    and aborts task execution if there are local changes in tracked files, unless force parameter is set to true.