DEV Community

Craig Shoemaker
Craig Shoemaker

Posted on

1 1

My git aliases

I'm lazy.

Every day I need to sync up branches in git to account for the following:

  • Changes made to the remote main branch
  • Changes made to the current branch from the origin

In looking for ways to make to some simple shortcuts, I found Nicolas Fränkel's blog post on Creating Git shortcuts and How to get the name of the current git branch into a variable in a shell script? to be particularly helpful.

By using the techniques described in each of these articles in concert, I have defind the following git aliases.

open

Opens the current folder in Visual Studio Code.

alias open="code ."
Enter fullscreen mode Exit fullscreen mode

get-branch

Sets $branch as the current branch.

alias get-branch="branch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')"
Enter fullscreen mode Exit fullscreen mode

sync-branch

Pulls the branch set to $branch from the origin.

alias sync-branch="git pull origin $branch"
Enter fullscreen mode Exit fullscreen mode

sync-main

Pulls the remote main branch into the current branch.

alias sync-main="git pull upstream main"
Enter fullscreen mode Exit fullscreen mode

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay