git checkout <hash> # non named commit
git checkout <branch_name> # named commit
The two lines above will place the HEAD pointer on the given commit. You should know that a branch name is a commit, except it can evolve if a new commit is added when you're on that branch.
If you want to place your branch Dev on the commit ad4f43af43e you can do this
git branch -f Dev ad4f43af43e
Be careful! This is dangerous because you may lose commits.
Answer from smarber on Stack Overflowgit checkout <hash> # non named commit
git checkout <branch_name> # named commit
The two lines above will place the HEAD pointer on the given commit. You should know that a branch name is a commit, except it can evolve if a new commit is added when you're on that branch.
If you want to place your branch Dev on the commit ad4f43af43e you can do this
git branch -f Dev ad4f43af43e
Be careful! This is dangerous because you may lose commits.
If you're looking to branch out from a specific commit of a branch, first be sure you are in the branch,
git checkout dev
Now I want to checkout a specific commit 123654 from the dev branch to a new branch while keeping the head on main branch.
git checkout -b new-branch 123654
git - How to branch from a previous commit - Stack Overflow
Is this the way to checkout a repo to a specific commit?
git filter-branch doesn't seem to remove files from old commits when I "git checkout xxxx"
Is there a straight-forward way to switch between git commits in VS Code?
Create the branch using a commit hash:
git branch branch_name <commit-hash>
Or by using a symbolic reference:
git branch branch_name HEAD~3
To checkout the branch while creating it, use:
git checkout -b branch_name <commit-hash or HEAD~3>
To do this on github.com:
- Go to your project.
- Click on the "Commits".
- Click on the <> ("Browse the repository at this point in the history") on the commit you want to branch from.
- Click on the "tree: xxxxxx" up in the upper left. Just below the language statistics bar, you'll get the option to "Find or Create Branch" (just type in a new branch name there)

I asked someone what version of a repo they used for an analysis and they gave me a hash for a commit.
Is this the correct way to access the version they used?
-
git clone https://github.com/foo.git
-
cd foo
-
git checkout -b bar <hash she gave me>
This should give me the repo in the state of the commit hash she gave me correct?