How to Create a Git branch from a Commit Example |Video upload date:  · Duration: PT3M1S  · Language: EN

Quick guide to create a Git branch from a specific commit with commands for finding the hash creating the branch checking out and pushing

Want to branch off a moment in time and pretend you never wrote that terrible function That is exactly why Git lets you create a branch from a specific commit. This short guide shows the exact git commands you need and a few survival tips for future you or your teammates in devops.

Why make a branch from a commit

Creating a branch from a commit is how you explore a historical snapshot without rewriting history. Use it to recover work from an old commit to build a hotfix or to start a fresh feature from a reliable point in version control. It is safe and reversible and it keeps the commit graph honest.

Common use cases

  • Resurrecting a bug fix that lived in an abandoned branch
  • Starting a hotfix from a release commit
  • Experimenting without touching main or master

Step by step commands

Here are the plain git commands that do the job. No magic, no rewriting of history, no regrets.

1 Find the commit hash

Use your favorite log view. The terminal option is compact and reliable.

git log --oneline

Copy the short hash like 1a2b3c4 or the full one if you enjoy being precise.

2 Create the branch

Make a branch that points at that historical commit.

git branch new-branch 1a2b3c4

If you want to create and switch in one move use git checkout -b with the commit hash.

git checkout -b new-branch 1a2b3c4

3 Switch to the branch

If you used git branch then switch with this.

git checkout new-branch

Your working tree and index will reflect the state of that commit so you can develop from that exact snapshot.

4 Publish the branch

Share it with the team when you want others to continue the work.

git push -u origin new-branch

Quick checklist for the forgetful

  • Use git log --oneline to find the commit fast
  • Name the branch with a reason or a date so future you does not cry
  • Avoid creating the branch on the wrong remote head by double checking origin

Tips and gotchas

If the commit is very old be explicit in the branch name like hotfix/2025-09-02-repro-fix or recover/old-feature That saves time when you are hunting for where a fix came from later.

Remember that creating a branch from a commit does not rewrite history. It simply creates a new pointer. If you need to move history around that is a different set of git-commands that deserve their own tutorial and more coffee.

There you go You now know how to create a branch from a commit with the basic git-commands git-branch git-checkout and git-push This trick is a small but useful tool in any version control toolbox for developers and teams working in devops.

I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!

This is a dedicated watch page for a single video.