Commit No Bug
Published on

Speeding Up Your Git Workflow: Simple Aliases That Save Hours

Authors
  • avatar
    Name
    nikUnique
    Twitter
Promotional graphic for Git workflow optimization with a rocket, clouds, and space theme, featuring text about speeding up Git workflows with simple aliases.

Committing and pushing code is among the most repetitive tasks in development. Without aliases, your day might look like this:

git add -A
git commit -m "some message"
git push origin feature/my-branch

Multiply that by dozens of commits across a week, and you're spending real time on boilerplate (Sure, if AI agents do the job for you, then this doesn't matter. But if you code yourself sometimes, then this makes a difference). I did it myself in three lines over and over again until one day I realized how ineffective it was and decided to automate the process. These aliases collapse multiple commands into one-liners, letting you stay focused on coding.

Taking a Look At Each Alias

AliasWhat It DoesBest Used For
commitStages all files and commits with a generic messageQuick checkpoints without a custom message
commitMsgStages all files and commits with your custom messageMeaningful commits with proper descriptions
pushStages, commits with a generic message, and pushes to your current branchRapid iterations that don't need a detailed message
pushMsgStages, commits with your custom message, and pushes to your current branchProduction-ready commits ready to share

How to Use Them

Add them to your package.json:

{
  "scripts": {
    "commit": "git add -A && git commit -m \"Quick checkpoint\"",
    "commitMsg": "bash -c 'git add -A && git commit -m \"$1\"' --",
    "push": "git add -A && git commit -m \"Quick checkpoint\" && git push origin $(git rev-parse --abbrev-ref HEAD)",
    "pushMsg": "bash -c 'git add -A && git commit -m \"$1\" && git push origin $(git rev-parse --abbrev-ref HEAD)' --"
  }
}

Then use them with npm run:

npm run commit
npm run commitMsg "Add dark mode toggle"
npm run push
npm run pushMsg "Add dark mode toggle"

You can actually make names even shorter.

The Smart Default: Branch-Aware Pushing

The key innovation here is git rev-parse --abbrev-ref HEAD, which automatically detects your current branch and pushes to it.

This means the same command works everywhere. On main? It pushes to main. On feature/dark-mode? It pushes there. On hotfix/critical-bug? Pushes there too. You never have to think about which branch you're targeting; the tool figures it out.

This eliminates the most dangerous mistake these shortcuts could make: accidentally pushing to main when you wanted to push to a feature branch. By respecting your current branch instead of hardcoding a target, you get safety by default.

Making These Truly Global

If you want these shortcuts available everywhere on your pc, not just in projects with package.json, add them as shell aliases in your ~/.bashrc or ~/.zshrc:

alias gc="git add -A && git commit -m 'Quick checkpoint'"
alias gcm="bash -c 'git add -A && git commit -m \"\$1\"' --"
alias gp="git add -A && git commit -m 'Quick checkpoint' && git push origin \$(git rev-parse --abbrev-ref HEAD)"
alias gpm="bash -c 'git add -A && git commit -m \"\$1\" && git push origin \$(git rev-parse --abbrev-ref HEAD)' --"

Reload your shell with source ~/.bashrc (or ~/.zshrc), and then test with gc to confirm it works. Or you can close and open the terminal, and it should be there already.

The Real Benefits

Speed

You cut the command count from 3–4 lines to 1. For a developer making 20 commits a day, that's 40–80 lines of typing you eliminate.

Fewer Mistakes

Combining commands reduces the chance of forgetting a step. No more committing without pushing, or pushing without staging. And you can't push to the wrong branch (Unless you are on the wrong branch :)).

Mental Load

Less context switching. You're not breaking flow to think about Git syntax or which branch to target; you're just running one command and moving on.

When to Use Each One

Use commit when:

  • You're making frequent, small iterations during active development
  • You don't need a detailed message because you might do a lot of commits, and writing a custom message to every one of them could distract you from the main thing at hand. At least for me, it did.
  • You're not ready to push yet

Use commitMsg when:

  • You're making a meaningful change worth documenting
  • You want a message in your history, but aren't pushing immediately
  • You need to review the commit before pushing

Use push when:

  • You're iterating rapidly and need speed
  • You're on a personal feature branch
  • The changes don't need detailed documentation

Use pushMsg when:

  • You want to commit and push in one step with a proper message
  • You're working alone or on a feature branch
  • You're confident in the changes

Important Caveats

Staged vs. Unstaged Changes

git add -A stages everything, including deletions. Make sure you actually want all those changes committed before running these aliases. If you're uncertain, run git status first.

Commit Message Quality

The generic "Quick checkpoint" message is fine for personal feature branches, but use commitMsg or pushMsg when you need to document your changes for others or for your future self.

The Safety Advantage: Why This Design Prevents the Main Branch Mistake

These shortcuts assume you're pushing to branches you own. In team workflows where main is protected, these commands are actually safer because they'll push to your feature branches without the risk of accidentally pushing to main.

Conclusion

These aliases work because they remove friction without sacrificing safety. By using your current branch as the default, the tool adapts to your workflow instead of forcing you into one. Whether you're shipping solo or on a team, you've got a shortcut system that saves time every single day, and as said before, without sacrificing safety.

Found this helpful? Please share it with someone who also might find it helpful. Would you like more posts from me? Subscribe to the newsletter. Got questions? Send an email to commitnobug@outlook.com.