Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MangaD/248dccfe064f079b825b2ac4b9ee32a7 to your computer and use it in GitHub Desktop.
Save MangaD/248dccfe064f079b825b2ac4b9ee32a7 to your computer and use it in GitHub Desktop.
10 Useful Git Aliases to Boost Your Productivity

10 Useful Git Aliases to Boost Your Productivity

CC0

Disclaimer: ChatGPT generated document.

Git aliases can save you time by allowing you to create shortcuts for commonly used commands. Here are some useful and commonly used Git aliases, along with instructions on how to add them to your Git configuration:

1. Checking Git Status

  • Alias: st
  • Command: git status
  • Add it:
    git config --global alias.st status

2. View Git Log in One Line

  • Alias: lg
  • Command: git log --oneline --graph --decorate --all
  • Add it:
    git config --global alias.lg "log --oneline --graph --decorate --all"

3. Show Last Commit

  • Alias: last
  • Command: git log -1 HEAD
  • Add it:
    git config --global alias.last "log -1 HEAD"

4. Add All and Commit

  • Alias: cm
  • Command: git commit -am "message"
  • Add it:
    git config --global alias.cm "commit -am"

5. Fetch and Rebase

  • Alias: up
  • Command: git pull --rebase
  • Add it:
    git config --global alias.up "pull --rebase"

6. View Unstaged Changes

  • Alias: unstaged
  • Command: git diff
  • Add it:
    git config --global alias.unstaged diff

7. View Staged Changes

  • Alias: staged
  • Command: git diff --cached
  • Add it:
    git config --global alias.staged "diff --cached"

8. Amend Last Commit

  • Alias: amend
  • Command: git commit --amend
  • Add it:
    git config --global alias.amend "commit --amend"

9. Show Changes in the Current Branch Compared to Another

  • Alias: compare
  • Command: git diff --stat
  • Add it:
    git config --global alias.compare "diff --stat"

10. List All Git Aliases

  • Alias: alias
  • Command: git config --get-regexp ^alias\.
  • Add it:
    git config --global alias.alias "config --get-regexp ^alias\."

How to Add Git Aliases:

To add these aliases, you can either use the git config command as shown above, or you can manually add them to your Git configuration file. Here's how:

  1. Open your global Git configuration file (~/.gitconfig) in a text editor.
  2. Add the following under the [alias] section:
    [alias]
        st = status
        lg = log --oneline --graph --decorate --all
        last = log -1 HEAD
        cm = commit -am
        up = pull --rebase
        unstaged = diff
        staged = diff --cached
        amend = commit --amend
        compare = diff --stat
        alias = config --get-regexp ^alias\.

By adding these aliases, you'll be able to type shorter commands and boost your productivity when using Git.

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