re: Productivity 101: Git Aliases for Lazy Developers VIEW POST


Why put git aliases in the .bashrc file? This implies a specific shell, in a specific OS (or set of).

I have aliases in my .bashrc, but none of them are git related.

My git aliases are in my .gitconfig file.

Things like 'git acp "message"' - add, commit push, with a commit message. 'git cof ' to check out a particular file, from a particular branch.


I think a lot of devs like a single source of truth for all of their aliases, regardless of the tools the aliases interact with. Both approaches are absolutely acceptable. No need to "bash" anybody else ;)


It's the OO dev in me - Single Responsibility Principle. ;)

Could you not apply that same principle to a .bash_profile with all your system's aliases?

Of course, but I wouldn't put things like this into .bash_profile - .bashrc is preferred (for me). I'm not always in a login shell.

To me, git configuration, like shortcuts & PGP keys (that I shared with the OP) should be in the .gitconfig file, so if I'm looking to change them, that's the first place I'd look (on someone else's system/login).

CLI shortcuts, such as renaming "git" to "g" are correct in .bashrc - and indeed, you could reference git aliases from bash aliases, but at some stage, I think we descend into acronym hell. gpf expanding to git push -f would be OK, but I've seen some bad examples too.


yeah, I understand the angle you are coming from. Uncoupling git aliases from the shell environment is a better way to go, thanks for the feedback. Nice git aliases :)


My full .gitconfig (sanitised), if you're interested. Steal/borrow whatever you feel might be useful.


(and yes, my Bash Aliases has "g=git", so I can do things like g acp "commit msg")

Lol 😂 Nicee! I will borrow some 😉

Since sharing is caring, I also have the branch (and some identifiers) on my terminal prompt.


function parse_git_branch() {
    BRANCH=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
    if [ ! "${BRANCH}" == "" ]
        echo " (${BRANCH}${STAT})"
        echo ""
function parse_git_dirty {
    status=`git status 2>&1 | tee`
    dirty=`echo -n "${status}" 2> /dev/null | grep "modified:" &> /dev/null; echo "$?"`
    untracked=`echo -n "${status}" 2> /dev/null | grep "Untracked files" &> /dev/null; echo "$?"`
    ahead=`echo -n "${status}" 2> /dev/null | grep "Your branch is ahead of" &> /dev/null; echo "$?"`
    newfile=`echo -n "${status}" 2> /dev/null | grep "new file:" &> /dev/null; echo "$?"`
    renamed=`echo -n "${status}" 2> /dev/null | grep "renamed:" &> /dev/null; echo "$?"`
    deleted=`echo -n "${status}" 2> /dev/null | grep "deleted:" &> /dev/null; echo "$?"`
    if [ "${renamed}" == "0" ]; then
    if [ "${ahead}" == "0" ]; then
    if [ "${newfile}" == "0" ]; then
    if [ "${untracked}" == "0" ]; then
    if [ "${deleted}" == "0" ]; then
    if [ "${dirty}" == "0" ]; then
    if [ ! "${bits}" == "" ]; then
        echo " ${bits}"
        echo ""

export PS1="[\u@\h \[\033[32m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\]] $ "

Wow, what does this script do?

Obviously don't add it if you don't understand it (never trust a random on the internet).

But to answer your question, this:
Terminal Image

On any terminal prompt in a git repository, I see username/hostname/path (as normal), but then the git branch (in yellow) followed by some "bit flags". In the picture, the exclamation mark tells me I have modified some file(s), the question mark tells me I've added some file(s). Just after a commit, the bit flags disappear to tell me that the working directory is "clean."

There's other flags, as described in the script. If I'm not in a git repo, I just see the normal terminal.

code of conduct - report abuse