2

I got my git aliases in my .bash_aliases file. Since yesterday, when I want to add alias like alias gpuo='git push --set-upstream origin'. First, he doesn't find it and secondly, he open ups this file every time I open up a new terminal window. Also, I get prompted with 2 files to edit. But there is only one bash alias file. I checked it with the find command.

The contents of .bash_aliases are:

alias g='git'
alias gst='git status'
alias ga='git add'
alias gb='git branch'
alias gc='git checkout'
alias gcb='git checkout -b'
alias gpo='git push origin'
alias gf='git fetch'
alias gcm='git commit -m'
alias gp='git pull'
alias grom='git rebase origin/master'
alias gstash='git stash'
alias gstasha='git stash apply'
alias upgrade='sudo apt-get update && sudo apt-get dist-upgrade && sudo apt-get autoremove'
alias cl='clear'
alias alias='vim ~/.bash_aliases'
1

The original poster found the solution while inspecting ~/.bash_aliases and provided it in an edit:

As I rewriting my question as suggested in the comments, I noticed there where an alias which I called alias. That caused recursive behavior. Thanks for the push in the correct direction ;)

To expand on that a bit, this was the line in ~/.bash_aliases that caused the problem, which could simply be removed:

alias alias='vim ~/.bash_aliases'

Strictly speaking, the problem was not caused by recursion. bash does not expand aliases recursively. For example, most Ubuntu users have alias ls='ls --color=auto', and this does not cause any problems; the ls in the alias definition is not itself expanded.

Instead, the problem with defining an alias called alias is that subsequent attempts to use the alias command to define aliases use the alias alias instead. In this case, running alias ... had the effect of running vim ~/.bash_aliases ..., which would run vim and open ~/.bash_aliases while also trying to open files named by the arguments passed for ....

When the alias command is used in the usual way to define aliases, it has one argument (e.g., gpuo='git push --set-upstream origin'). This explains the observation that two files were opened:

Also, I get prompted with 2 files to edit.

If such files were saved, their names would have an = sign in them. It might be worth looking for such files to check that they were created unintentionally and then delete them. But if they weren't saved, vim would not have created them.

  • Thanks for clearing that up. I wouldn't be able to explain this in that manner. – Maxstgt Sep 4 at 8:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.