Git push failed inside pipeline [Azure DevOps]

Last day I was struggling with the git error inside the pipeline.
The pipeline code was simple, it should change branch into the existing one, add one file there and push it into git

  
- bash: |
      git switch $(NEW_BRANCH)
      git pull origin $(NEW_BRANCH)
      ...
      git add -A
      git commit -m "Commit message"
        
      git push origin $(NEW_BRANCH)

However, this error occurred every time

error: failed to push some refs to 'https://.../_git/...'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and integrate the remote changes
hint: (e.g. 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

I tried many multiple things, changing git switch to git branch, tried to use git rebase – no success!
But then I tried to modify pull to pure git pull – and it worked!!!

Working code:

  
- bash: |
      git switch $(NEW_BRANCH)
      git pull
      ...
      git add -A
      git commit -m "Commit message"
        
      git push origin $(NEW_BRANCH)