Branching, Committing, and Pushing Changes

Branching

  1. When making changes to an existing file, it is best practice to create a new branch so that the changes you are making can stay isolated till you are ready to merge them to the document/file. To create a branch in Intellij, click + New Branch from the branch dropdown. Currently, it will say main since you have the main branch checked out, but we will soon create/checkout a new branch called test_change and then displayed branch name will change from main → test_change:

    JetBrains
  2. You will be prompted to enter a name for the new branch. For this example we will use test_change as an example. Make sure Checkout branch is checked and click Create:

    JetBrains
    JetBrains
  3. You will be taken back to the file editing view and you will see that the name of the branch in dropdown has updated to test_change.

    JetBrains

Committing

  1. Now that you have created a new branch, we can commit the changes that we made to the branch. To easily view the changes, switch to IntelliJ’s Commit view and double click on the file. The Commit view will only show files that have changes made to them, making it easy to see where changes have been made. The changes you have recently made that have not yet been committed will be highlighted in the pane to the right.

    JetBrains
    JetBrains
  2. If the changes you’ve made look good, then we can move on to committing them. First, check the boxes next to the files that you’ve Edited. Next, enter a logical commit message that describes the changes you’ve made and then click Commit at the bottom.

    JetBrains
  3. Once the commit is completed, you will be taken back to the file edit view. To confirm that the changes you made were indeed committed you can view the commits on the branch.

    JetBrains
  4. Clicking the git icon highlighted above will open a view that shows all the commits on the branch. As you can see, the commit we just made is at the top.

    JetBrains