Quick references for basic task with git
For easier tasks, just use Smart Git to make things visually. However, it’s paid
- Download and install GIT (to use command lines): Git’s Homepage
- Git client tools: Github Desktop (Windows, MacOS, Linux), Smart Git (Windows, Linux, macOS - Native M1), Source Tree
- Git GUI for Terminal: lazygit
# Info Usergit 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 changegit config core.fileMode false
# Disable pull rebasegit config pull.rebase false
# Format displaygit config color.ui truegit config format.pretty oneline
If you want to configure for all repositories. You can use the option --global
Multi-column
Check status
git statusgit status -s #modified date
Remote
git remote -v
Check logs commit:
# With colorsgit log --online --graph --color --all --decorate
# --grap: draw text-based branches# --decorate: display name and tagsgit log -- <file>
# Check commit containing <file>git log --prep='abc'
# Look for commits containing "abc" in their namegit log <from>..<to>
# display commits from <from> to <to># Check current HEADgit log -1 # Something likes HEAD -> <branch-name>
Check the changes of some file
git diff <file>git diff <file> > file_name.patch # Save the changes to another filegit show <file>
Check the list of files in the last commit
# Get the last commit idgit log --format="%H" -n 1
# list of filesgit diff-tree --no-commit-id --name-only -r <commit_id>