Search code examples
pythongitcomparefilesystemsgitpython

Git checkout and scan subdirectories using python


How do I git checkout two branches and check for differences in subdirectories? Ideally, the scrip would do the following:

  1. Checkout two different copies of upstream.
  2. Scan both copies for different files and missing files.
  3. Include the users who modified the files last, the timestamp of the last change and users email.

Solution

  • Your script could use the git worktree command in order, from one local cloned repository, to checkout two different branches in two separate folders.
    (note: a Python library like gitpython does not support directly git worktree -- issue 719 -- but you can still call that git command)

    For each file differences between the two branches, you can query through git log the last commit author/date of said file.