Create a Git branch from another branch
Choose a local or remote-tracking branch as a starting point, control upstream tracking, and understand how the new branch diverges.
Run git switch -c <new-branch> <source-branch> to create a branch at the source branch’s current tip and switch to it. The source branch keeps its existing tip; subsequent commits on the new branch do not move it.
Create and switch in one step
For a feature based on your local develop branch:
git switch -c feature/login develop
The older equivalent is git checkout -b feature/login develop. Choose one command. If switching to the selected starting point would overwrite uncommitted work, Git can refuse the operation; preserve that work before trying again.
To create the branch without switching:
git branch feature/login develop
You can then run git switch feature/login later. Alternatively, switch to develop first and create the branch from the current HEAD without naming a starting point.
Start from a remote-tracking branch
Refresh the remote information when you need the latest fetched state:
git fetch origin
git switch --no-track -c feature/login origin/develop
This assumes your fetch configuration includes origin/develop. A remote-tracking ref is a local record of fetched state, not a live view of the server.
--no-track avoids automatically treating origin/develop as the new feature branch’s upstream. When ready to publish the feature under its own name:
git push -u origin feature/login
Branch prefixes such as feature/, bugfix/, and hotfix/ can make purpose clear. Follow the repository’s naming conventions.
Keep the branch up to date deliberately
Both branch names initially reach the same commit and its ancestors. Later changes on develop do not automatically appear on the feature branch. While on the feature branch, you can merge develop, or rebase onto it according to the team’s workflow. Rebasing rewrites commits, so coordinate any rewrite of shared work.
If the branch began on the wrong base, a command such as this can transplant a selected commit range:
git rebase --onto main wrong-base feature/login
Use it only after verifying that the commits selected by wrong-base..feature/login are exactly the work you intend to replay. Save a retaining branch at the original tip first. This is not a universal fix: branch movement, merges, conflicts, and shared commits can make that range inappropriate. An ordinary rebase also does not preserve merge structure unless configured to do so.
Frequently asked questions
Does deleting the source branch delete the new one?
No. They are separate references. Commits still reachable from the new branch remain reachable even after the source branch is deleted.
Can Git tell me which branch this one was created from?
git merge-base feature/login develop finds a best common ancestor in the current graph. It does not prove the original branch-creation point, especially after merges or rebases. Use git log --oneline --graph --all to inspect the history and local reflogs when available; branch names do not store a permanent “created from” field.
References
Contact us
Join the community
to join the community
Try Guance
Start online and pay only for what you use.
Get startedChoose a Guance plan