Q:

Fetch all the branches in git and get Hashcode for all the branches

I am trying to get a command in git which can help me fetch list of all the branches or my code and also list down all the hashcode in front of same . As I want to delete all my stale branches and keep it safe for later retrieval.
To List all the branches following command is enough.
Git branch -r 

to get the hashcode for a branch
git rev-parse <BranchName>

can I get one command where it list all branches and hashcode in front of it.

A:

 git for-each-ref refs/remotes --format="%(objectname) %(refname:lstrip=2)"

git for-each-ref outputs information on all local refs.
refs/remotes is the pattern for remote tracking branches. Only the refs matching the pattern will be printed.
--format formats the output. Here %(objectname) refers to the commit hash. A following space is literally a space. %(refname) refers to the ref name. The full name of a remote tracking branch is like  refs/remotes/origin/foo. :lstrip=2 suppresses the left 2 parts refs and remotes.
See git for-each-ref for more.

