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:

  • Alias for submodules
  • git branch with no commits
  • How do I force-quit Git Bash?
  • How to tell git branch name from commit hash?
  • Git won't add certain globs
  • Why doesn't my bash prompt update?
  •  * [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?

  • Can a git repository be created where branches are clones from other repositories?
  • How not to ignore an item locally which is in .gitignore_global
  • Delete all .SVN folders in paths with embedded blanks
  • How does commit signing work?
  • Commit in git only if tests pass
  • Why GIT commit displays my organization name and email rather than my name and email?
  • 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.