3

I know that git branch lists all local branches.
But is there a way to list also the branches that existed, but were deleted?

My usage for this is for naming purposes.

If a feature was implemented earlier on some branch and that branch after it deleted, when lot later working on the same functionality, want to reuse the same name of the branch.

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
Vuk Djapic
  • 816
  • 13
  • 29
  • Checkout [how to get git log display name of (deleted) branches](http://stackoverflow.com/a/12114948/7274758) – Libin Varghese Mar 10 '17 at 09:31
  • You may be able to find some recently-checked-out branches in reflog, but in general: branch names are not something Git cares about tracking. Why do you care about reusing the same branch name? It doesn't make any difference to Git whether the new branch name is the same or different as something else that Git has forgotten about. – ephemient Mar 10 '17 at 09:51
  • If you never delete the branches from the remote, `git branch -a` would work, assuming that you always push your feature branches. – 1615903 Mar 10 '17 at 10:13
  • @ephemient I care about branch name, as it is scope for a feature that is implemented. For example, to later find al commits on branch name X, which are related to feature X. – Vuk Djapic Mar 10 '17 at 10:24
  • @Libin Checked the answer, seems that only eligible option is to not delete the branches. But it can lead to lot of branch names with no way of telling which are current ones. – Vuk Djapic Mar 10 '17 at 10:24
  • @VukDjapic: This should help. http://stackoverflow.com/questions/1307114/how-can-i-archive-git-branches – Libin Varghese Mar 10 '17 at 10:28

1 Answers1

0

IMO a nice and reliable way to do that is through git tags. When a feature is done, you create a git tag and in the comment you include the branch name.

  git tag -a v1.4 -m "<branch_name> blabla"

This way, you can list tags and indirectly the branches that existed:

  # outputs tags with their comments
  git tag -l -n

  #output would be
  v1.1     <feature_branch_name> comment blabla
  v1.2     <other_feature_branch_name> other_comment blabla
  ....
smarber
  • 4,829
  • 7
  • 37
  • 78