Ooh git common aliases improve efficiency by half

·

3 min read

Using short Git aliases helps to improve the efficiency of your daily use of Git. The ultimate linux environment for mac has a very rich alias naming built in, so here are some common aliases I've used in the course of using Git.

To set these Git aliases you need to set them in .zshrc or .bashrc (windows specific), which is usually located in the HOME directory of your computer.

Alias abbreviations

gaa

git add .

gcm

Add all changes to the staging area

git commit -m

gca

Move the currently saved file to the previous commit, -no-edit means that the previous commit will be kept, i.e. the new content in the currently saved file will not be deleted

git commit --amend --no-edit

gwait

Cancel all staged files

git reset HEAD

gundo

Cancels the last commit and moves the files in the commit to the staging area.

git reset --soft HEAD^

gl

Show commit information (commit hash, commit date, branch name, commit record and author)

git log --pretty=format:"%C(yellow)%h\\ %C(green)%ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=short --graph

gco

Branch switching

git checkout

gps

Update the remote

git push

gpsf

Forces the local branch to overwrite the remote branch, which is determined to be safer than git push --force.

git push --focre-with-lease

gpl

Get the update from the remote and rebind the local branch with the upstream branch, clearing the redundant merge commit information

git pull --rebase

grb

Rebase the current branch with another branch

git rebase

grba

Terminates the git rebase operation and restores the git state to the point at which the git rebase command was started

git rebase --abort

grbc

Generally used to continue git rebase after resolving commit conflicts

git rebase --continue

gdno

Compare file changes to show only the corresponding file list

git diff --name-only

gd

Compare file changes

git diff

gss

Show the file modification status of the lite version

git status -s

gmnf

Normal merge (no fast forward)

git merge --no-ff

Default aliases

There are already rich git alias defaults available for windows, macos and other systems.

windows

[alias]
 aa = add -A
 cm = commit -m
 ca = commit --amend --no-edit
 wait = reset HEAD
 undo = reset --soft HEAD^
 lg = log --pretty=format:"%C(yellow)%h\\\ %C(green)%ad%Cred%d\\\ %Creset%s%Cblue\\\ [%cn]" --decorate --date=short --graph
 co = checkout
 ps = push
 psf = push --force-with-lease
 pl = pull --rebase
 rb = rebase
 rba = rebase--abort
 rbc = rebase--continue
 dno = diff --name-only
 d = diff
 ss = status -s
 mnf = merge --no-ff

macos

alias gaa='git add -A'
alias gcm='git commit -m'
alias gca='git commit --amend --no-edit'
alias gwait='git reset HEAD'
alias gundo='git reset --soft HEAD^'
alias glg='git log --pretty=format:"%C(yellow)%h\\ %C(green)%ad%Cred%d\\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=short --graph'
alias gco='git checkout'
alias gps='git push'
alias gpsf='git push --force-with-lease'
alias gpl='git pull --rebase'
alias grb='git rebase'
alias grba='git rebase --abort'
alias grbc='git rebase --continue'
alias gdno='git diff --name-only'
alias gd='git diff'
alias gss='git status -s'
alias gm='git merge --no-ff'

Did you find this article valuable?

Support Jweboy by becoming a sponsor. Any amount is appreciated!