Last active
February 2, 2023 14:02
-
-
Save yasinkacmaz/deec8c6d2936c66e80f86d01a14694c2 to your computer and use it in GitHub Desktop.
Yasin Git Command Aliases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I don't like super short aliases that git offers by default. | |
# For example gaa for -git add .- or gc for checkout or commit | |
# These aliases seem to me more natural, easier to remember as they mostly named as the operation intended | |
# Some of these aliases can be used easier with a text editor set to Git. | |
# Here is how to do it: https://docs.github.com/en/get-started/getting-started-with-git/associating-text-editors-with-git | |
# I also recommend using .zsh with ohmyzsh extension with autosuggestions and autocomplete plugins. It will make typing these aliases much faster. | |
# Here is how: https://techviewleo.com/how-to-install-zsh-and-oh-my-zsh-on-macos-big-sur/ | |
# You can copy-paste the entire text to .zshrc and it will work as intended. | |
# My OhMyZsh Plugins: | |
# plugins=(zsh-autosuggestions zsh-syntax-highlighting zsh-completions git gitfast) | |
# For windows, no need on mac | |
# Useful on Windows with Turkish language. | |
# This command sets cmd.exe, bash.exe language to English which doesn't break typing when characters like ğ,ü entered | |
export LANG="en_US.UTF-8" | |
export TERM=cygwin | |
export DEFAULT_USER="$(whoami)" # Useful for WSL(Linux Subsystem on Windows) | |
# ---------------------- | |
# YaSo* Git Command Aliases | |
# ---------------------- | |
# Status | |
alias stat='git status' | |
alias status='git status' | |
alias br='git branch' | |
alias branch='git branch' | |
# Cancel all of non commited changes(HARD RESET) | |
alias reset='git reset --hard HEAD' | |
alias resethead='git reset --hard HEAD' | |
# Cancel last commit, keep changes(SOFT RESET) | |
# This will delete your last commit but will keep changes as not commited. | |
# I mainly use this alias instead of -git stash-. More reliable, easy to edit message, add or remove files. | |
alias cancel='git reset HEAD~' | |
alias cancellast='git reset HEAD~' | |
alias addall='git add .' | |
alias add='git add .' | |
alias commit='git commit' | |
alias amend='git commit --amend' | |
# Branch | |
# These commands expect a parameter. Proper use: delete feat/abc -> deletes feat/abc branch | |
alias delete='git branch -D $1' | |
alias select='git checkout $1' | |
alias switch='git switch -c $1' # switch = creates a new branch with current branch as head (This command is added on a later version of Git, please update it to latest) | |
alias fetch='git fetch origin $1' | |
alias fetchdev='git fetch origin development' | |
alias fetchmaster='git fetch origin master' | |
alias fetchmain='git fetch origin main' | |
# Branch: feat/abc -> If someone force pushes to this branch, I can call update and get the latest code | |
# This is useful when 2 person working on the same branch, or you work on the same branch using 2 different computers | |
alias update='git pull --rebase origin `git rev-parse --abbrev-ref HEAD`' | |
# Send and push | |
alias push='git push origin `git rev-parse --abbrev-ref HEAD`' | |
alias pushforce='git push origin `git rev-parse --abbrev-ref HEAD` --force-with-lease' | |
# Rebase and Cherry | |
alias rebasedev='rebase development' | |
alias rebasemaster='rebase master' | |
alias rebasemain='rebase main' | |
alias rebasecontinue='git rebase --continue' | |
alias cherrycontinue='git cherry-pick --continue' | |
alias rebaseabort='git rebase --abort' | |
alias cherryabort='git cherry-pick --abort' | |
# pr feat/xx -> fetch origin/feat/xx and create a branch | |
# I mostly use this one when someone opens a pull request and I need to fetch the branch | |
alias pr='createBranchFromPr' | |
# Usage: create branchName remoteBranch -> fetch origin/remoteBranch and create branchName from origin/remoteBranch | |
alias create='createBranchFromOrigin' | |
# Usage: createdev feat/abc -> create a branch from development | |
alias createdev='createBranchFromDev' | |
# For kotlin lint check (Remove if you are non Kotliner) | |
alias kc='./gradlew ktlintCheck --continue' | |
# This command needs some explanation. Usage: interactive 7 | |
# This command will open your text editor with latest 7 commits, presented to you to update them. | |
# You can reorder commits, drop(remove) some of them, edit commit messages, squash multiple commits into one commit, stop on commits to edit them | |
# Basically you can change history of a branch(actually a repo) if you have given force push rights. | |
# I mostly use this one when working on a feature branch with lots of small commits. Trying to edit their message, merge smaller ones into a bigger commit etc. | |
# I highly recommend having a default text editor on git(sublime, vscode, notepad++) to easily use it. | |
alias interactive='interactiveRebase' | |
createBranchFromPr() { | |
branchname="$1" | |
`git fetch origin $branchname` | |
`git checkout -b $branchname origin/$branchname` | |
} | |
createBranchFromOrigin() { | |
branchname="$1" | |
remote="$2" | |
`git fetch origin $remote` | |
`git checkout -b $branchname origin/$remote` | |
} | |
createBranchFromDev() { | |
branchname="$1" | |
`createBranchFromOrigin $branchname development` | |
} | |
rebase() { | |
branchname="$1" | |
`git fetch origin $branchname && git rebase origin/$branchname` | |
} | |
interactiveRebase() { | |
count="$1" | |
`git rebase -i HEAD~$count` | |
} | |
# Fixes android emulator's wrong date/hour/time by setting it to the current time | |
fixdate() { | |
adb root | |
sleep 2s | |
adb shell "date $(date +%m%d%H%M%G.%S)" | |
} | |
# Enable/Disable wifi proxy for charles without going to the wifi settings manually | |
alias charlesProxyEnable='adb shell settings put global http_proxy 192.168.1.4:666' | |
alias charlesProxyDisable='adb shell settings put global http_proxy :0' | |
# ---------------------- | |
# Other aliases | |
# ---------------------- | |
alias cls='clear' # command from cmd.exe | |
alias gradle='./gradlew' | |
chmod +x gradlew |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment