Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pipes in a Git alias?

Tags:

git

bash

unix

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?

like image 425
Lee Hampton Avatar asked Oct 22 '13 18:10

Lee Hampton


People also ask

What are aliases in git?

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.

How can add a git URL as an alias?

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 .

Where do I put git alias?

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' .

What is exclamation in git?

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.


2 Answers

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 '*' … 
like image 169
Michael Krelin - hacker Avatar answered Sep 23 '22 07:09

Michael Krelin - hacker


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.

like image 42
forivall Avatar answered Sep 23 '22 07:09

forivall