DEV Community

Craig Shoemaker
Craig Shoemaker

Posted on

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

Top comments (0)