Skip to content

Instantly share code, notes, and snippets.

@BinaryKitten
Last active September 20, 2018 15:16
Show Gist options
  • Save BinaryKitten/4451336 to your computer and use it in GitHub Desktop.
Save BinaryKitten/4451336 to your computer and use it in GitHub Desktop.
Useful GIT Aliases
Useful Aliases
lastcommit
shows you the last commit made on the current branch
git lastcommit
git config --global alias.lastcommit "log --pretty=oneline -n 1 --no-merges"
merge-branch
Checks out branch, updates that branch. Then checks back out to last branch and merges specified branch in
git merge-branch <branchname>
open ~/.gitconfig in editor. Add following below [alias] block
merge-branch = !sh -c 'git checkout $1 && git update $1 && git checkout - && git merge $1' -"
create-branch
creates a branch
git create-branch <newBranch>
open ~/.gitconfig in editor. Add following below [alias] block
create-branch = "!sh -c 'git branch $1 && git checkout $1 && git push origin $1 && git branch --set-upstream $1 origin/$1' -"
create-branch-from
creates a branch from another
git create-branch-from <newBranch> <anotherbranch>
open ~/.gitconfig in editor. Add following below [alias] block
create-branch-from = "!sh -c 'git checkout $2 -b $1 && git checkout $1 && git push origin $1 && git branch --set-upstream $1 origin/$1' -"
delete-tag
Deletes a tag from local & remote
git delete-tag <tag>
open ~/.gitconfig in editor. Add following below [alias] block
delete-tag = "!sh -c 'git tag -d $1 && git push origin :refs/tags/$1' -"
delete-branch
Deletes a branch from local & remote
git delete-branch <branch>
open ~/.gitconfig in editor. Add following below [alias] block
delete-branch = "!sh -c 'git branch -D $1 && git push origin :$1' -"
merge-to
merges the current branch into the target after making sure target is up to date
open ~/.gitconfig in editor. Add following below [alias] block
merge-to = "!sh -c 'git checkout $1 && git pull origin $1 && git merge - && git push origin $1 && git checkout - ' -"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment