Skip to content

Instantly share code, notes, and snippets.

@yudapc
Last active July 3, 2023 02:06
Show Gist options
  • Save yudapc/0270bf3249a77805b834d2203787cb5f to your computer and use it in GitHub Desktop.
Save yudapc/0270bf3249a77805b834d2203787cb5f to your computer and use it in GitHub Desktop.
Git
[user]
name = Yuda Cogati
email = [email protected]
[alias]
# checkout a branch
co = "checkout"
# checkout a new branch
cob = "checkout -b"
# adds all changed files
cam = !git commit -am
# adds all changes including untracked files
acam = !git add -A && git commit -m​
# Get my working directory up to date. git pull --rebase --prune && git submodule update --init --recursive
up = !git pull --rebase --prune $@ && git submodule update --init --recursive
lg = "log --pretty=oneline --abbrev-commit"
lgp = log -p
credit = shortlog -sn
hist = "log --graph --pretty=format:'%Cred%h%Creset %d %s %Cgreen(%cr)%Creset %Cblue[%an]%Creset' --abbrev-commit --date=relative"
ahead = "log @{u}...HEAD --graph --decorate --left-right --boundary --pretty=format:'%Cred%h%Creset %d %s %Cgreen(%cr)%Creset %Cblue[%an]%Creset' --abbrev-commit --date=relative"
today = "log --stat --since='1 Day Ago' --graph --pretty=oneline --abbrev-commit --date=relative"
# Show verbose output about tags, branches, or remotes
tags = "tag -l"
branches = "branch -a"
remotes = "remote -v"
file-count = "status | grep 'modified:' | wc -l"
purge-remote = "remote update origin --prune"
uncommit = "reset HEAD~1"
# list all git aliases
la = "!git config -l | grep alias | cut -c 7-"
# archive the repo
tar = ! "tar() { git archive --format tar --prefix=\"${PWD##*/}/\" HEAD -o ${1}; }; tar"
targz = ! "targz() { git archive --format tar.gz --prefix=\"${PWD##*/}/\" HEAD -o ${1}; }; targz"
zip = ! "zip() { git archive --format zip --prefix=\"${PWD##*/}/\" HEAD -o ${1}; }; zip"
st = status -sb
br = branch -vv
bra = branch -vv --all
update-submodules = submodule update --init --recursive
upgrade-submodules = submodule update --init --remote
[color]
ui = auto
interactive = auto
[color "branch"]
current = yellow reverse
local = yellow
remote = green
[color "diff"]
meta = yellow bold
frag = magenta bold
old = red bold
new = green bold
[color "status"]
added = green
changed = magenta
untracked = bold yellow
[color "grep"]
match = cyan bold
selected = blue
context = normal
filename = magenta
linenumber = green
separator = yellow
function = blue
[credential]
helper = cache --timeout=3600
[help]
autocorrect = 5
[push]
default = matching
---------------------
Git checkout branch
---------------------
$ git checkout -b branch_name origin/branch_name
---------------------
Git branch refresh
---------------------
$ git branch -a
or
$ git branch -r
$ git remote update origin --prune
---------------------
Git delete branch
---------------------
local:
$ git branch -D BRANCH_NAME
origin:
$ git push origin --delete BRANCH_NAME
---------------------
Git reorder commit with rebase
---------------------
example :
$ git rebase -i HEAD~3
edit commit by message, usualy order by old time
---------------------
Git cherry-pick from another branch
---------------------
$ git checkout master
$ git cherry-pick 62ecb3
---------------------
Git delete commit on remote
---------------------
$ git push -f origin HEAD^:master
---------------------
Git merge with squash
---------------------
menggabungkan semua commit di branch tanpa commit:
$ git checkout master
$ git pull --rebase
$ git checkout namabranch
$ git rebase master
$ git checkout master
$ git merge --squash namabranch
menggabungkan semua commit di branch dengan commit:
$ git merge namabranch
---------------------
Git mirror
---------------------
git clone --bare https://source.gitrepository/repo.git destination_folder
git push --mirror https://newrepo/repo.git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment