Create and switch branches
#A branch names a commit. switch -c creates and checks out a branch. Switching updates the index and working tree as allowed; incompatible local edits can block it.
Fragment
Reference
Inspect, save, combine and recover work with clear command effects.
Modern Git CLI, including switch and restore (Git 2.23+). Independent examples use illustrative paths and branch names. Inspect status and diffs before changing files or history. Commands below are reference material, not executed by this guide.
A branch names a commit. switch -c creates and checks out a branch. Switching updates the index and working tree as allowed; incompatible local edits can block it.
Fragment
Detached HEAD names a commit directly rather than a branch. A new commit can be retained by creating a branch before leaving it.
Fragment
origin is a conventional remote name, not a special server type. origin/main is a local remote-tracking reference updated by fetching.
Fragment
fetch downloads objects and updates the configured remote-tracking refs. It does not merge those changes into the current branch.
Fragment
Effect: fetched objects/refs change; your checked-out files are not integrated.
pull fetches and then integrates. --ff-only accepts an update only when the current branch can fast-forward.
Fragment
A divergent branch needs an explicit merge or rebase decision; pull does not always mean merge.
push sends objects and requests remote ref updates. -u records an upstream for later commands.
Fragment
Remote policy can reject an update. Bare --force-with-lease compares against your remote-tracking ref, which a background fetch can silently update; add --force-if-includes (or set push.useForceIfIncludes), or name the expected value with --force-with-lease=<ref>:<sha>. It still rewrites history; agree on that workflow first.
An annotated tag stores a message and metadata. Tags do not advance when new commits are created.
Fragment
branch -m renames a branch; -d deletes one only when Git’s merge checks permit it. -D bypasses that check. Deleting a branch name does not remove arbitrary working files.
Fragment
Switch away before deleting a checked-out branch; other worktrees can also hold it.
A local branch can track a remote-tracking branch. The upstream supplies defaults for selected status, pull and push behavior, subject to configuration.
Fragment
Remote-tracking references are local observations updated by fetch; they are not live server branches.
A remote is a named set of fetch/push configuration. Adding it or changing its URL does not move the local branch or integrate remote history.
Fragment
Names and URLs are examples. Separate fetch and push URLs are supported when that workflow is intentional.