DEV Community

Michael Z
Michael Z

Posted on • Edited on • Originally published at michaelzanggl.com

Git aliases for increased productivity

It's been almost a year since I posted my first article on git aliases. Since then I've applied a number of additional aliases in my workflow. Be sure to check out my first article here to how I use "git update", "git nah", and "git amend".


Without further ado, here they are:

git arrange

This command lets you arrange all commits you made in a feature branch. Perfect for cleaning up commits before creating a PR.

Register alias

git config --global alias.arrange "rebase -i develop"
Enter fullscreen mode Exit fullscreen mode

git recent

If you often find yourself switching branches, this is a lifesaver. It will list all branches sorted by recent use.

Register alias

git config --global alias.recent "branch --sort=-committerdate" # most recent branches
Enter fullscreen mode Exit fullscreen mode

git stash-unstaged

Ever wanted to stash your code, but keep everything you staged (with git add .)

Register alias

git config --global alias.stash-unstaged "stash save --keep-index -u"
Enter fullscreen mode Exit fullscreen mode

git undo-commit

This will allow you to remove the latest commit and move all the changes back into your working directory. With this, I often prefer committing instead of stashing code that I need for later, because it makes it so much simpler than searching through a list of stashes.

Register alias

git config --global alias.undo-commit "reset HEAD~ --soft"
Enter fullscreen mode Exit fullscreen mode

What aliases did you apply in your workflow? Let me know in the comments ✌️


If this article helped you, I have a lot more tips on simplifying writing software here.

Top comments (3)

Collapse
 
claudiofreitas profile image
Claudio Freitas

This one is saving me a lot of headache lately.

git config --global alias.set-upstream "!git branch --set-upstream-to=origin/`git symbolic-ref --short HEAD`"
Enter fullscreen mode Exit fullscreen mode

Then everytime you receive the message

There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/<branch> branch-name
Enter fullscreen mode Exit fullscreen mode

just run

git set-upstream
Enter fullscreen mode Exit fullscreen mode

It is util when your local branch names are the same as in your remote.

Collapse
 
michi profile image
Michael Z • Edited

I don't recall running into this after having set the push.default option to current stackoverflow.com/a/948397

Only thing I have to do is add the -u flag to the push command once to set the upstream. (git push -u)

Collapse
 
moopet profile image
Ben Sinclair

These are good!