FIND YOUR NEXT FEW LINES

The snippet library.

Small, practical examples. Search by task or narrow things down below.

10 snippets foundClear filters
GitBranches & ancestry

Count commits unique to each of two branches

Git: The symmetric difference with left-right separates commits reachable from only one side.

Git✓ Tested
GitBranches & ancestry

Create a branch from a known release tag

Git: A named starting revision makes the branch’s initial commit explicit.

Git✓ Tested
GitBranches & ancestry

Delete an already merged practice branch

Git: The lowercase -d option refuses to delete an unmerged branch in ordinary use.

Git✓ Tested
GitBranches & ancestry

Find branches that contain a selected commit

Git: branch --contains limits the list to branches whose histories include the chosen revision.

Git✓ Tested
GitBranches & ancestry

Inspect a revision with detached HEAD

Git: Detached mode is useful for inspection; create a branch before keeping new work.

Git✓ Tested
GitBranches & ancestry

List branches already merged into the current branch

Git: The merged filter reports branches whose tips are reachable from HEAD.

Git✓ Tested
GitBranches & ancestry

Read the current branch name

Git: show-current returns an empty string when HEAD is detached.

Git✓ Tested
GitBranches & ancestry

Rename the current branch

Git: branch -m changes the local branch name without creating a new commit.

Git✓ Tested
GitBranches & ancestry

Return to the previously checked-out branch

Git: The dash shorthand selects the previous branch in the checkout history.

Git✓ Tested
GitBranches & ancestry

Test whether one revision is an ancestor of another

Git: merge-base --is-ancestor reports its answer through the exit status.

Git✓ Tested