Introduction


Branches


Figure 1

These graph diagrams show repositories with different numbers of branches. The vertices, or circles, in these graphs show different commits, and each horizontal path is a branch. The first shows a repository with 1 main branch, the second a repository with 1 main and 1 feature branch, and the third repository 1 main and 2 feature branches.


Figure 2

Creating a new branch. When you run git checkout -b my_branch your new branch gets created and checked out, meaning you are now on your new branch (represented by the smiley face). Any commits you make will be on this branch until you checkout another one.


Figure 3

Every time you run the git commit command the commit will be added to your current branch.


Figure 4

Switching branches using git checkout.


Figure 5

Merging new commits from the main branch into the feature branch with git merge main.


Figure 6

Merging new commits the feature branch into the main branch with git merge my_branch.


Figure 7

Rebasing the feature branch onto new commits in the main branch with git rebase main.


Pull Requests


Figure 1

Creating a Pull Request: If you recently pushed changes to your branch you may see a button that says “Compare and Pull Request” on GitHub.


Figure 2

Creating a Pull Request: Give your Pull Request a title and description.


Figure 3

The conversation tab of a Pull Request.


Figure 4

The conversation tab of a Pull Request. Scroll to the bottom of the page to leave a comment.


Figure 5

The Files Changed tab of a Pull Request, showing what the proposed changes are for the Pull Request. You can click the + next to a line number to leave an in-line comment.


Figure 6

After clicking the “Merge Pull Request” button on the conversation, click “Confirm Merge” to merge the pull request.


Git Workflows