Skip to content

Git

Add hist to aliases

[alias]
    hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=format:'%Y-%m-%d %H:%M'

Change comment of last commit

git commit --amend

Branch

# create new branch
git checkout -b {branch_name}

# delete branch locally
git branch -d {BranchNameDelete}

# delete branch locally, that not merged
git branch -D {BranchName}

# delete branch remotely
git push origin --delete {BranchName}

# Prune branches
git remote prune origin
git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | xargs git branch -D

Checkout to remote branch

git checkout -b {branch} origin/{branch} 

Tag

# show tags on HEAD
git tag --points-at HEAD
# add
git tag {tagname}
# push to origin
git push origin --tags

# delete
git tag -d {tagname}
# push delete
git push origin --delete {tagname}

Rollback to commit

git reset --hard {commit}
git push -f

git log

git log -5 --pretty=format:"%h %ad | %s%d [%an]"

gitignore

# ignore directory content, but not directory
dir/*
!dir/.gitkeep