DEV Community

Cover image for Running bash commands with git alias
Gonçalo Morais
Gonçalo Morais

Posted on • Originally published at on

Running bash commands with git alias

This is a quick tip I learned recently and it allowed me to improve my git workflow a bit more.

Here’s a new part of my .gitconfig:

    main = !git checkout main && git pull --no-tags
    sync = !git main && git switch -
    fuse = !git sync && git rebase main

Enter fullscreen mode Exit fullscreen mode

This week I added these three alias to my .gitconfig but, if you notice, they are not “regular” alias. The ! at their beginning tells Git that these are not alias to Git commands, but rather bash commands.

This gives you a simple but powerful way to chain executions, so I created three related alias that I can call depending on my goal:

  • If I finished working on a branch and I want to get back to main and start with the most recent codebase, I’ll run git main. Notice the --no-tags, this is motivated by working on a large monorepo and not needing all the tags of the packages we keep updating;
  • If I’m working on a branch and I want to quickly get any changes made to our main branch but come back to the branch I’m in right now, I’ll call git sync. As a note, git switch - gets you back to the branch you were before you moved to the current branch you are now;
  • Finally, if I want to bring the current branch I’m at up to speed with the latest code we’ve shipped, I’ll use git fuse. It will do everything I described on the other commands so far and rebase our main branch onto the current branch I’m at.

Cover image by @yancymin

Top comments (0)