I'm trying to create a git alias to automate some of the more annoying Git tasks I need to do. One of which is setting the upstream of a new branch. So I decided to write a Bash script to do it.
However I'm having some difficulties figuring out how to store the return value of a git command in a bash variable.
I have the below code, but it gives me the following errors when I run it.
environment: line 0: local: `rev-parse': not a valid identifier
environment: line 0: local: `--abbrev-ref': not a valid identifier
What do I need to be able to execute the full git rev-parse --abbrev-ref HEAD and store its value in a variable so that I can use it later?
This function is being written in my .gitconfig.
[alias]
setupstream = "!f() 
            { 
                local branchName=git rev-parse --abbrev-ref HEAD; 
                echo $branchName; 
            }; 
            f"
