This repository contains some tips for git
.
Oh My Zsh is an open source, community-driven framework for managing your zsh configuration.
Installation zsh:
Ubuntu:
$ sudo apt-get install zsh
Arch Linux:
$ sudo pacman -S zsh
Installation Oh My Zsh:
$ sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
$ chsh -s $(which zsh)
Enable auto updates - set DISABLE_UPDATE_PROMPT
to true
:
$ less ~/.zshrc
...
DISABLE_UPDATE_PROMPT="true"
...
Plugins (see GitHub wiki for more plugins) can be activated in plugins
sections:
$ less ~/.zshrc
...
plugins=(git ripgrep)
...
See other plugins: git, ripgrep, python, pip, rust, kubectl, docker, docker-compose
Git commands/aliases with Oh My Zsh git plugin:
Short | Command |
---|---|
g | git |
gst | git status |
ga | git add |
gco | git checkout |
gd | git diff |
gdw | git diff --word-diff |
gdca | git diff --cached |
gdcw | git diff --cached --word-diff |
Pre-push script: pre-push
- will warn if pushing to protected branch, script is available in GitHub repository.
To enable english messages add alias in Shell RC file (bash - .bashrc
, zsh - .zshrc
) at the end of the file (to avoid anomalies):
alias git='LANGUAGE=en_US.UTF-8 git'
alias git_compare_word='git diff --no-index --word-diff'
alias diff_git_word='git_compare_word'
alias git_compare='git diff --no-index'
alias diff_git='git_compare'
- GitUI provides you with the comfort of a git GUI but right in your terminal
Pushing empty commit (example 3), e.g. with releasing Docker image:
git commit -m "[pre-release] Test docker image" --allow-empty
Amending commit with current date (example 2):
git commit --amend --date=now
Rebase with master branch:
git rebase master
Rebase current branch in interactive mode (example 1):
git rebase -i HEAD~3
Getting some-file.txt from master branch:
gco master -- some-file.txt
Check last 2-commit changes:
git diff HEAD~2
or shorter:
gd HEAD~2
Comparing master and develop branches:
git diff master..develop
Comparing 2 non-git files: 1.txt and 2.txt:
git diff --no-index --word-index 1.txt 2.txt
shorter:
gdw --no-index 1.txt 2.txt
Comparing 2 non-git directories dir1 and dir2:
git diff --no-index dir1 dir2
shorter:
gd --no-index dir1 dir2
Comparing changes with context (only changes will be available - context may be changed by U argument):
git diff -U0
Comparing only deleted changes:
git diff --diff-filter=d
One line commits:
git log --oneline
Stash uncommitted changes:
git stash
Pop stashed changes:
git stash pop
List stashed changes:
git stash list
Drop stashed changes (stashed changes are indexed from 0)
git stash drop stash@{0}
or remove all:
git stash clear
Search with grep in git:
git grep 'my_secret_password'
- Example 1 - remove empty commit using
git rebase -i
- read README for details
- branch rebase_interactive
- Example 2 - override commit message and fix typo
- read README for details
- branch commit_amend
- Example 3 - add empty (without changes) commit (with message only)
- read README for details
- branch commit_empty