Comparing & Moving File Structures, Files, and Code Between Two Branches in PyCharm

  1. Open Your Project in PyCharm:

    • Launch PyCharm and open the project that is under Git version control.
  2. Accessing the Version Control System:

    • Go to View > Tool Windows > Git or press Alt+9 (on Windows/Linux) or Cmd+9 (on macOS) to open the Version Control window.

Comparing Branches for Overall Structure:

  • In the Version Control window, switch to the Log tab.
  • Select the two branches you want to compare by holding Ctrl (or Cmd on macOS) and clicking the branch names.
  • Right-click and select Compare with <BRANCH> or just Compare if you want to compare two branches other than the one you are currently on.

Viewing File Structure Differences:

  • The differences between the branches will be displayed in a new tab. It shows commits that are unique to each branch.
  • To see file structure differences, click on a commit. PyCharm will show the list of files changed in that commit.
  • You can expand each file to see the specific lines of code that were changed.

Comparing Working Tree:

  • In the Version Control window, switch to the Log tab.
  • Here, you'll see a list of branches at the top. Select the branch you want to compare.
  • Right-click and select Show Diff with Working Tree.

  • The Working Tree will change to show the difference between your current branch and the one you selected
  • Click on a file, and the diff viewer allows you to see line-by-line differences in the file between the two branches.
  • Right-click on a file and wil allow you to show the differences and even copy the whole file using  Get from Branch.

Comparing Individual Files:

  • To compare an individual file across branches, find that file in the Project view.
  • Right-click the file and choose Git > Compare with Branch....
  • Select the other branch you want to compare it with. PyCharm will open a diff viewer showing changes side by side.
  • This diff viewer allows you to see line-by-line differences in the file between the two branches.
  • You can pick changes from the code using the >> in every single difference



Comparing File Structures, Files, and Code in Visual Studio Code

  1. Open Your Repository in VS Code:
    1. Start VS Code and open the folder containing your Git repository.
  2. Install GitLens (if not already installed):
    1. GitLens is an extension for VS Code that enhances its Git capabilities.
    2. Go to the Extensions view by clicking on the square icon on the left sidebar or pressing Ctrl+Shift+X (Windows/Linux) or Cmd+Shift+X (macOS).
    3. Search for "GitLens" and install it.


Comparing Branch File Structures:

  • Open the Source Control panel by clicking the branching icon on the left sidebar or pressing Ctrl+Shift+G (Windows/Linux) or Cmd+Shift+G (macOS).
  • In the Source Control panel, you'll find Branches. Click it and select it. 

    • OR right-click on the file and select Open Changes

  • Select the branch you want to compare against, right-click on the file and select Compare with Upstream to compare with your current branch.
  • GitLens will display the file structure differences between the branches, including added, deleted, and modified files.

Comparing Individual Files:

  • Within the changes displayed by GitLens, click on a file to open the diff view.
  • This view will show you the differences in that file between the current branch and the selected branch, side by side.
  • You can move or apply all the changes in a file. Right-click on the file and select Apply Changes

Comparing Code Within Files:

  • The side-by-side diff viewer in VS Code allows you to examine the specific code changes line by line.
  • Changes are highlighted, with additions and deletions clearly marked.
  • You can move code changes from one branch to another by clicking on the arrow on the side of the change


    1. In the Version Control window, switch to the Log tab.