# Create and switch to a Git branch without losing edits

Canonical: https://githtml.com/guides/git-create-and-switch-branch
Published: 2026-11-23
Publisher: WaveTech LLC / gitHtml

Use git switch -c with a new branch name to create and enter a branch from the current commit. Check your current branch and working changes first. Uncommitted edits are not automatically owned by the old branch; they may follow you when switching is safe, while conflicting changes cause Git to stop.

## Choose the starting commit deliberately

A branch name points to a commit and advances as you commit on that branch. Creating a branch does not copy the entire project into another folder, and it does not automatically update your starting point from a server. If you create a branch while on an old local main, your new work starts from that old commit.

Inspect status and the recent log before deciding. If the task should begin from an updated remote branch, fetch and review that reference first. Do not automatically pull or reset a shared checkout just to create a branch. Existing uncommitted changes may belong to a different task, so understand them before carrying them into the new branch.

## Create the branch in the existing checkout

The example starts from the current commit and uses a task-oriented name. It does not push the branch or create a pull request. If the name already exists, inspect it instead of using a force-create option that could move the existing branch unexpectedly. Keep branch names descriptive enough to distinguish concurrent work.

1. If Git refuses because switching would overwrite local edits, preserve and inspect those edits; do not add a force option to silence the protection.
2. If you intended an existing branch, use git switch with that exact local branch name rather than creating a second similarly named branch.

````shell
git status --short
git branch --show-current
git log -1 --oneline
git switch -c fix/retry-limit
git status --short --branch
````

## Confirm where the next commit will land

After switching, check the branch name and staged diff before committing. The important outcome is that your next commit advances the intended branch. Working files alone cannot tell you this because two branches may currently contain identical snapshots. An editor’s branch indicator is helpful, but the terminal check is explicit and easy to include in a handoff.

A new local branch has no automatic remote counterpart unless your command or configuration establishes one. Publish it separately when the work is ready and the destination is known. If you merely need to inspect an older file, a read-only command may avoid switching altogether. Branch creation should support an actual line of work, not become a ritual for every repository reading task. Keep unrelated edits intact throughout the transition.

Do not rename the current branch merely because a suggested name already exists. An existing branch can contain important work even when it is not currently checked out.

## Sources and further reading

- [Git reference: git-switch](https://git-scm.com/docs/git-switch)
- [Git reference: git-branch](https://git-scm.com/docs/git-branch)

## Related guides

- [Create an annotated Git tag for a verified revision](https://githtml.com/guides/git-create-annotated-tag-deliberately)
- [Make your first Git commit and verify its contents](https://githtml.com/guides/git-create-first-commit-checklist)
- [See staged and unstaged changes with git diff](https://githtml.com/guides/git-diff-staged-versus-unstaged)
- [Understand fast-forward merges and merge commits](https://githtml.com/guides/git-fast-forward-versus-merge-commit)

Editorial approach: https://githtml.com/guides/about
