Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checkout git branch with only the first few characters of a branch name

Tags:

git

Is there a command I can use where I can say git checkout branch_na* and it would autocomplete and checkout that branch?

like image 773
masterforker Avatar asked Mar 09 '23 22:03

masterforker


2 Answers

I don't know of a way to use wildcards like * in that context. However, there is a Git bash autocomplete script where you can press <Tab> to autocomplete partially typed branch names at the shell prompt.

like image 102
Greg Hewgill Avatar answered Mar 14 '23 05:03

Greg Hewgill


I was just wondering if git support wildcards

Using it as you mention would rely on the bash (which does not know anything about branches)

So you need to rely on other means to other mean, like:

git checkout $(git for-each-ref --format='%(refname:short)' refs/heads/branch_na.*|head)
like image 31
VonC Avatar answered Mar 14 '23 07:03

VonC