Question

I figured out that git branch | grep <something> | cut -d' ' -f2 will give me the name of a branch that contains the substring <something>. I'm trying to put this command in a git alias, like so:

[alias]
    gb = "!f(){ git branch | grep $1 | cut -d' ' -f2; };f"
    # ...

However, this does not work; it just produces a blank line. How do I fix this?

Was it helpful?

Solution

As indicated by the commenter above, the fix is to use awk '{print $NF}' instead of the cut command.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top