• Skip to primary navigation
  • Skip to main content
Sal Ferrarello
  • About Sal Ferrarello
  • Speaking
  • Connect
    Mastodon GitHub Twitter (inactive)
You are here: Home / Dev Tips / Compare composer.json on Two Different Git Branches

Compare composer.json on Two Different Git Branches

Last updated on October 25, 2022 by Sal Ferrarello

I have composer.json files on two different branches and I want to compare their (non-dev) dependencies. This is the command I run to compare the require section of composer.json on my current branch to the require section of composer.json on the branch env_qa.

diff <(jq --sort-keys '.require' composer.json) <(git show env_qa:composer.json | jq --sort-keys '.require')

I’m using jq to extract the dependencies under the require key in composer.json.

Sal Ferrarello
Sal Ferrarello (@salcode)
Sal is a PHP developer with a focus on the WordPress platform. He is a conference speaker with a background including Piano Player, Radio DJ, Magician/Juggler, Beach Photographer, and High School Math Teacher. Sal can be found professionally at WebDevStudios, where he works as a senior backend engineer.

Share this post:

Share on TwitterShare on FacebookShare on LinkedInShare on EmailShare on Reddit

Filed Under: Dev Tips, Solution Tagged With: composer, Git, jq

Reader Interactions

Comments

  1. Chrispian Burks says

    October 26, 2022 at 9:39 am

    Excellent tip! This is gonna come in super useful. But even more so, learning about jq for the first time. Adding to my toolbox.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2023 · Bootstrap4 Genesis on Genesis Framework · WordPress · Log in