Git

Quick references for basic task with git

For easier tasks, just use Smart Git to make things visually. However, it’s paid

Installation & Tools

Setting on Local Environments

Terminal window
# Info User
git config user.name "namnh198" git config user.email "namnhn98@gmail.com"
# Save token login (Don't need to login again every time we use this user)
git config credential.helper store
# Don't track file & folder permissions change
git config core.fileMode false
# Disable pull rebase
git config pull.rebase false
# Format display
git config color.ui true
git config format.pretty oneline

If you want to configure for all repositories. You can use the option --global

Check the status

Multi-column

Check status

Terminal window
git status
git status -s #modified date
Remote

Terminal window
git remote -v

Check logs commit:

Terminal window
# With colors
git log --online --graph --color --all --decorate
# --grap: draw text-based branches
# --decorate: display name and tags
git log -- <file>
# Check commit containing <file>
git log --prep='abc'
# Look for commits containing "abc" in their name
git log <from>..<to>
# display commits from <from> to <to>
# Check current HEAD
git log -1 # Something likes HEAD -> <branch-name>

Check the changes of some file

Terminal window
git diff <file>
git diff <file> > file_name.patch # Save the changes to another file
git show <file>

Check the list of files in the last commit

Terminal window
# Get the last commit id
git log --format="%H" -n 1
# list of files
git diff-tree --no-commit-id --name-only -r <commit_id>