Use pipeline to only deploy changed files
Asked by finnruijter:

Hi there!  

I'm using the following .yml file to push the repo to WPengine. Problem with these commands is that it deploys all. Is it possible to only deploy the changed files in the commit? What should the commands be?

pipelines:  
branches:  
master:  
- step:  
name: Deploy to production  
deployment: production  
script:  
- git filter-branch -- --all  
- git push --force git@git.wpengine.com:production/XXX.git master  
- echo "Pushed to Production"

<br />

dev:  
- step:  
name: Deploy to dev production  
deployment: dev  
script:  
- git filter-branch -- --all  
- git push --force git@git.wpengine.com:production/XXX.git dev  
- echo "Pushed to Dev Production"

Thanks in advance!


Answers:
author: Theodora Boudale
body: Hi [@finnruijter](/t5/user/viewprofilepage/user-id/4359549),

I suspect (although I'm not entirely sure) that this may have to do with the use of *--force* option to push, as this option will force the remote repo (in this case the WPengine repo) to take the version of the branch that exists in Pipelines.

Just to understand the issue a bit better before I proceed with suggestions, where exactly and how do you see that all files are being deployed, instead of only the files in the last commit?

Kind regards,  
Theodora

comments: author: finnruijter
body: Hi [@Theodora Boudale](/t5/user/viewprofilepage/user-id/818086) !

Thank you for your answer. Removing --force sadly results into a failed deployment. I'm using this document from WPengine to configure the deployment: <https://wpengine.com/support/deploying-code-with-bitbucket-pipelines-wp-engine/>.

![Screenshot at Jul 21 14-12-56.png](https://community.atlassian.com/t5/image/serverpage/image-id/152186iB367ABD4BFD10308/image-size/large?v=v2&px=999 "Screenshot at Jul 21 14-12-56.png")


author: Theodora Boudale
body: Hi [@finnruijter](/t5/user/viewprofilepage/user-id/4359549) ,

Thank you for the info.

The first question I would like to ask is whether you are pushing changes to master branch of this WPengine repo from elsewhere, e.g. if there is anyone from your team or another Pipelines step, or if you have a script or tool that pushes to master branch of this repo. This is one possible cause for this error.

If the above is not the case, i.e. if only this Pipelines step pushes to master, then I suspect the command

```
git filter-branch -- --all
```

may be the culprit. I have tried testing your scenario by pushing to another Bitbucket repo, as I don't have a WPengine repo to test. Bitbucket repo 2 where I was trying to push is a fork of the repo where I was running Pipelines. Push without --force would fail when the above command was included in the yaml file, but it would succeed without it.

Is that command necessary for WPengine? I don't see it in the guide you linked here. My suggestion would be to try removing the above command, and also do a full clone in your Pipelines step, as I believe it is needed for pushing to the WPengine repo, see here: <https://community.atlassian.com/t5/Bitbucket-questions/Pipeline-issue-with-wp-engine/qaq-p/1667433>

```
master:
  - step:
      name: Deploy to production
      deployment: production
      clone:
        depth: full
      script:
        - git push git@git.wpengine.com:production/XXX.git master
        - echo "Pushed to Production"
```

Is this something that works for you?

Please do let me know about the question I asked initially as well, whether there is another Pipelines step, a script, a tool, or anyone from your team pushing to master branch of the WPengine repo. If this is the case, the above won't work, and we'll need to look into different options.

Kind regards,  
Theodora


Tags: bitbucket-pipelines

bitbucket-cloud

cloud