Git Branch Bash Variable Shortcut -
i trying create bash variable can use refer current branch in git: $branch.
when adding: branch=$(git symbolic-ref --short -q head) bash_profile, keep getting: fatal: not git repository (or of parent directories): .git when start new terminal.
furthermore, echo $branch not print out branch name, git symbolic-ref --short -q head would.
i'd able use not print out branch name (i have in prompt) things like:
git push origin $branch
which branch on depends on directory in. if have 2 git work trees, ~/a , ~/b, typing cd ~/a can put on 1 branch , typing cd ~/b can put on branch.
so trying set $branch in .bash_profile isn't going work. need update $branch every time change work trees, , after command can change branch of current work tree.
the simplest thing not set variable. instead, make alias:
alias branch='git symbolic-ref --short -q head 2>/dev/null' and use this:
git push origin $(branch) or if you're old-school:
git push origin `branch` if want set environment variable, simplest solution set every time print prompt:
_prompt_command () { export branch=$(git symbolic-ref --short -q head 2>/dev/null) } export prompt_command=_prompt_command note: should check .bash_profile , .bashrc see if you're setting prompt_command. if so, set branch in whatever function you're running prompt command.
Comments
Post a Comment