Git Cheat Sheet
Installation/Configuration
- System Level configuration:
- Edit
/etc/gitconfig, or git config --system
- Edit
- User Level configuration:
- Edit
~/.gitconfig, or git config --global
- Edit
- Project Level configuration:
- Edit
Project_Path/.git/config, or git configfrom project directory
- Edit
git --list to display current configurations
Other settings:
git --config --global core.editor "vim"to set vim as default editor
git --config --global color.ui true
- Auto Completion
- Copy raw source: git-completion.bash
- Save in root folder as a hidden file
.git-completion.bash - Add to
.bash_profileor.bashrc
if [-f ~/.git-completion.bash]; then
source ~/.git-completion.bash
fi - Git Prompt
- Copy raw source: git-prompt.sh
- Save in root folder as a hidden file
.git-prompt.sh - Add to
.bash_profileor.bashrc
if [-f ~/.git-prompt.sh]; then
source ~/.git-prompt.sh
export PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
fi Initializing a Repo
git init
git add .
git commit -m "message here" Creates a hidden directory (.git) in project directory, adds all files in . directory, commits all staged files
Log
git log -n 5
git log --since=2020-03-03
git log --until=2020-03-02
git log --author="name"
git log --grep="string"
git log --graph --all --oneline --decorate
git log --stat git log --format=medium other options:
- short
- oneline
- full
- fuller
- raw
git log -p - patch/shows an entire change set
Viewing differences
git diff - –staged
- –cached
- –color-words
- <SHA Value A>..<SHA Value B>
Other commands
git status
git show <SHA Value>
git commit -a
git reset HEAD file
git checkout <SHA Value> -- file
git revert <SHA Value>