Skip to content

Instantly share code, notes, and snippets.

@miere
Created February 7, 2022 22:50
Show Gist options
  • Save miere/75cc8ee12bef485087b6f538a9177f0e to your computer and use it in GitHub Desktop.
Save miere/75cc8ee12bef485087b6f538a9177f0e to your computer and use it in GitHub Desktop.

Useful Git Aliases

Here are a few aliases that I use on my daily routine. I'm sharing this as it might be helpful for other developers, too.

The Script

#!/bin/sh

# Push configuration will always assume same branch name in the given remote repository
# If only one remote location exists, it won't ask it.
git config --global push.default current

# Important aliases that prevents me to do mistakes
git config --global alias.update 'pull --rebase'
git config --global alias.publish 'push'
git config --global alias.fork 'checkout -b'
git config --global alias.amend 'commit --amend'

# Saves your current 
git config --global alias.save 'stash --'
git config --global alias.load 'stash pop'

# Shortcuts
git config --global alias.st 'status -s'
git config --global alias.ls 'log --oneline  --abbrev-commit'
git config --global alias.co 'commit'

Hands on

Switching between branches

Allows one to switch between branches using a more intuitive syntax.

git switch <my-branch>

Creating a new branch (forking) from the current one

Allows one to create a new branch using a more intuitive syntax.

git fork <new-branch-name>

Keeping your branch updated with the upstream repository

Merging remote upstream changes into your local repository is a common task in Git-based collaboration work flows. This particular alias will help you to keep things in sync without introducing merge commits, using a rebase strategy to solve conflicts.

git update

Publishing your changes to the upstream repository

Transfer commits from your local repository to a remote repo.

git publish

Temporarily saving your changes

Temporarily shelves changes you've made to your working copy so you can work on something else, and then come back and re-apply them later on.

git save

Loading temporarily saved changes

Loads previously shelved changes.

git load
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment