Skip to content

Instantly share code, notes, and snippets.

@technikhil314
Last active June 27, 2021 17:01
Show Gist options
  • Save technikhil314/8d1f6ae4872192057b08edc2ac5c8f71 to your computer and use it in GitHub Desktop.
Save technikhil314/8d1f6ae4872192057b08edc2ac5c8f71 to your computer and use it in GitHub Desktop.
My git aliases
alias gitHouseKeeping="git gc && git gc --prune && git remote prune origin && git prune && git clean -df"
git-amend-old() (
# Stash, apply to past commit, and rebase the current branch on to of the result.
current_branch="$(git rev-parse --abbrev-ref HEAD)"
apply_to="$1"
git stash
git checkout "$apply_to"
git stash apply
git add -u
git commit --amend --no-edit
new_sha="$(git log --format="%H" -n 1)"
git checkout "$current_branch"
git rebase --onto "$new_sha" "$apply_to"
)
commitwithstash() {
ga . && gsta && gc -m $1 && gstp
}
alias uncommit="git reset HEAD~1"
alias recommit="git commit --amend --no-edit"
alias editcommit="git commit --amend"
alias bfg="java -jar ~/installs/bfg.jar"
alias grss="git restore --staged"
revert() {
git revert $(git rev-parse HEAD)
}
resethard() {
git reset --hard $(git rev-parse --abbrev-ref --symbolic-full-name @{u})
}
squashlast () {
git rebase -i HEAD~$1
}
unalias gcl
gcl() {
dirName=$(basename $1 .git)
git clone $1
cd $dirName
}

How to use this?

  1. run echo $(basename $SHELL) and note the output of it on mac its generally zsh and on linux it will be bash
  2. if the above output
    • is zsh then copy all the contents of the file another file in this gist to $HOME/.zshrc
    • is bash then copy all the contents of the file another file in this gist to $HOME/.bashrc
  3. Restart your terminal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment