With some help from Learn Git Branching, here is are some 'Coles Notes':
Create a new branch:
git branch _branch_name_
Check out the new branch (for subsequent commits)
git checkout _branch_name_
Switch to the new branch (for subsequent commits, an alternative to checkout)
git switch _branch_name_
Create a new branch and check it out at the same time:
git checkout -b _branch_name_
Merging in Git creates a special commit that has two unique parents. A commit with two parents essentially means "I want to include all the work from this parent over here and this one over here, and the set of all their parents." To merge a branch into main/master, first checkout / switch to the primary branch.
git merge _branch_name_
Rebasing essentially takes a set of commits, "copies" them, and plops them down somewhere else. While this sounds confusing, the advantage of rebasing is that it can be used to make a nice linear sequence of commits. The commit log / history of the repository will be a lot cleaner if only rebasing is allowed.
git switch _branch_name_;git rebase master
To move back in time relative to a branch:
git checkout _branch_name_^
To move back in time relative to HEAD:
git checkout HEAD^
To move back in time relative a number of steps:
git checkout _branch_name_~2
Use relative refs to move a branch around:
git branch -f master HEAD~3
A git reset will move a branch backwards as if the commit had never been made in the first place. It is useful for local branches.
git reset HEAD~1
Git reset doesn't work for remote branches that others are using. In order to reverse changes and share those reversed changes with others, we need to use git revert.
git revert HEAD
To cherry-pick, means copy a series of commits below your current location (HEAD):
git cherry-pick _branch_name_1_ _branch_name_n_
Interactive rebase provides rebasing interactively to re-arrange and delete commits:
git rebase -i HEAD~4
HEAD can be modified with:
git commit --amend