Make New GIT Branch from Commit ID

·
1 min read
notes
#git #branch #cherrypick

Make a New Git Branch from Commit ID

If you want to create a new branch from an older commit (not the latest one), here’s how:

✅ Steps:

Find the commit hash:

Terminal window
git log --oneline

Example output:

e3a1b55 Fix security issue
6f24a1d Add README
34d2a5c Initial commit

Create a branch from that commit:

Terminal window
git checkout -b my-old-branch e3a1b55

Note:

  • Replace my-old-branch with your desired branch name.
  • Replace e3a1b55 with the actual commit hash.

Push the new branch (optional):

Terminal window
git push origin my-old-branch

🔄 If you’re already on another branch and don’t want to switch:

You can also do this without switching branches:

Terminal window
git branch my-old-branch e3a1b55

Then push:

Terminal window
git push origin my-old-branch