Skip to content

Instantly share code, notes, and snippets.

@malkab
Last active February 17, 2021 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malkab/469acf064fe296ae253ec91e751f8561 to your computer and use it in GitHub Desktop.
Save malkab/469acf064fe296ae253ec91e751f8561 to your computer and use it in GitHub Desktop.
Git - Working with branches

Comparing Branches

First, the term working tree refers to the current checked out branch, the working directory in it's present state.

It is recommended that comparison are made on commited, clean states, and not on uncommited changes. To compare with the current uncommited state of the working tree move the changes to staged. If not, new files won't show up at the SEARCH & COMPARE dialog, but this is tricky.

Use the VSC Git extension. To evaluate if a stalled branch is worth to be maintained, check out the develop, master, or main branch. If not very sure of the result, create a merge test branch.

Right click on the stalled branch and select Compare with Working Tree. The SEARCH & COMPARE section will read Compating XXX to Working Tree, being XXX the right clicked branch. The interpretation of the output is based on the changes to be done to XXX to reach the state of WT. Therefore:

  • a red - symbol means a file has been deleted: the file exists in XXX but not in WT;
  • a green + symbol means this is a new file: the file exists in WT but not in XXX;
  • a blue +- symbol means a file exists in both branches, but has changes: to the left, the WT version, to the right, the XXX one. The left side (WT) can be edited.

After reviewing changes, right click the stalled branch and select Merge Branch into Current Branch (the develop, master, or main one). In any case, the XXX branch will not be affected:

  • blue +- files: will generate merge conflicts or a straightforward fast-forward merge;
  • red - files: if the file was deleted at WT, will not be added. If not, they will be added to WT;
  • green + files: nothing will happen, they existed only at WT and there's nothing to do.

In merge conflicts, HEAD is WT.

If a test, security branch was created to test the merge, then select the real develop, master, or main and compare against the test branch to evaluate the merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment