I work on feature branches that have annoying big names, so I often end up grepping my current branch name when I need to push up to the feature branch from my local feature branch, like so:
git branch | grep '*' | sed 's/* //' | xargs git push origin
This works fine. I want to make this an alias, so I did this in ~/.gitconfig
:
[alias] pushcur = branch | grep '*' | sed 's/* //' | xargs git push origin
Now, when I run git pushcur
, I get the following error:
usage: git branch [options] [-r | -a] [--merged | --no-merged]
Leading me to believe that the alias is not properly parsing the pipes. Is there something else I should do to achieve the desired alias?
Git aliases are a powerful workflow tool that create shortcuts to frequently used Git commands. Using Git aliases will make you a faster and more efficient developer. Aliases can be used to wrap a sequence of Git commands into new faux Git command.
The simplest way to add a git alias is by running a command to add the alias to the git global configuration file. For example, running the command git config --global alias. hist "log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short" will add the alias git hist .
Your git aliases are often stored per your user's configuration at ~/. gitconfig . You can also manually set aliases using, for example, the command git config alias. s 'status -s' .
That means the Git status is normal. As soon as you start editing a file, the status changes to modified and the icon overlay then changes to a red exclamation mark. That way you can easily see which files were changed since you last updated your working tree and need to be committed.
I don't think you can, but you can prefix it with an !
to treat the command as a new shell command
[alias] pushcur = ! git branch | grep '*' …
I typically make small git-
scripts and put them in a directory that's in my path (~/.local/bin
). Check out git-extras for a bunch of good examples.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With