Git - sirdnt/quintessence GitHub Wiki

Basic

Configuration

global

git config --list
git config --global user.name "Name"
git config --global user.email "[email protected]"
git config --get remote.origin.url

git ignore global

git config --global core.excludesfile ~/.gitignore_global

local repository only

git config user.name "name"
git config user.email "[email protected]"

Basic

Checkout

git checkout <branch> checkout to a branch with it name
git checkout -b <branch> checkout create new branch with current change

Checkout remote branch with specific local branch
git checkout -b test origin/test

Branch

Check tracking branch of current branch

git branch -vv

Rename branch

on current branch : git branch -m
on other branch: git branch -m

Commit

git commit -m "commit message"

Amend commit

git commit --amend -m (optional)

Push

Push local change to new remote branch

git push -u
git push --set-upstream origin //push local branch to remote

merge

Check branchs haven't merged

git branch -r --no-merged origin/

Merge branch to current branch

git merge <branch name>

Advance

Working with diff command

git diff --param SHA1 SHA2

show only diff file from two commits with file name only git diff --name-only SHA1 SHA2

Log

git log --pretty=format:"%h%x09%an%x09%ad%x09%s"
git log --pretty=format:'%C(yellow)%h %Cred%ad %Cblue%an%Cgreen%d %Creset%s' --date=short
git log --pretty=format:'%C(yellow)%h %Cblue%>(12)%ad %Cgreen%<(7)%aN%Cred%d %Creset%s'

More info here

count source with diff or log

git diff --shortstat //show diff stat code not commit yet
git diff --shortstat SHA1 SHA2
git diff --shortstat 7b96fcf f25cdf2
git log --shortstat --oneline //stat show when log

Branch

check branchs haven't merged

git branch -r --no-merged <branch name> //local branch
git branch -r --no-merged origin/<branch name> //remote branch

Case branches deleted on remote but still exist on local

git remote prune origin (will remove all such stale branches)

Remove file already tracked by git on .gitignore

git rm -r --cached .
git add .
git commit -am "Remove should ignore files"

Reset

Reset local branch with remote branch

git reset --hard origin/<remote branch>

Reset to a commit

git reset --hard <commig hash>

Undo last commit and recommit again

git reset --soft HEAD~1
git commit -m "message"

If pushed to remote

git push -f //force push rewrite origin branch

Reset param: --soft,--mixed,--hard

  • --mixed (default): uncommit + unstage changes, changes are left in working tree.
  • --hard: uncommit + unstage + delete changes, nothing left.
  • --soft: uncommit changes, changes are left staged (index).
⚠️ **GitHub.com Fallback** ⚠️