Bad variable name in Bash from a Git alias

I have the following Git alias in my global git config.

pushnew = !f() { export tmp_branch=`git branch | grep '* ' | tr -d '* '` && git push --set-upstream origin $tmp_branch; unset $tmp_branch; }; f

When running it I get the following output:

  • “git add” using wildcard is not functioning as I hoped - must I cd into specific directories?
  • How can I run recursive find and replace operations on multiple files in parallel?
  • Git post-receive deployment stops working at random points
  • Using Bash to send space separated list of files to Git
  • How to “-@-expand (”${array}") possibly empty array in Bash when nounset is set?
  • Passing all parameters to a git alias
  •  * [new branch]      bug/graphs -> bug/graphs
    Branch bug/graphs set up to track remote branch bug/graphs from origin.
    f() { export tmp_branch=`git branch | grep '* ' | tr -d '* '` && git push --set-upstream origin $tmp_branch; unset $tmp_branch; }; f: 1: unset: bug/graphs: bad variable name
    

    I’ve seen this question but if that is the solution then how do I apply the fix within the context of a Git alias?

  • How to undo git pull from unrelated project?
  • Is there a way to setup remote-specific .gitignores?
  • Team member added hundreds of megs to git
  • How do I Re-root a git repo to a parent folder while preserving history?
  • Git: git checkout with modified working tree and index
  • How to setup a git repository where different users can only see certain parts?
  • One Solution collect form web for “Bad variable name in Bash from a Git alias”

    It should be:

    unset tmp_branch
    

    If you try unset $tmp_branch, the shell will substitute the value of $tmp_branch, trying to unset bug/graphs.

    Git Baby is a git and github fan, let's start git clone.