Skip to content

Instantly share code, notes, and snippets.

@jgpeak
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgpeak/7ed03143b1fab6f62829 to your computer and use it in GitHub Desktop.
Save jgpeak/7ed03143b1fab6f62829 to your computer and use it in GitHub Desktop.
Bash script to add helpful custom Git commands to a system.
# Description: Custom command to perform git add and git commit together.
# Execution Command: git add-commit -m 'My commit message'
git config --global alias.add-commit '!git add -A && git commit'
# Description: Custom command to update a branch with changes from the remote master.
# Execution Command: git update-branch
git config --global alias.update-branch '!git checkout master && git pull && git checkout - && git rebase master'
#Description: Custom command to remove all merged local branches
# Execution Commad: git remove-merged
git config --global alias.remove-merged '!git checkout master && git branch --merged | grep -v "\*" | xargs -n 1 git branch -d'
# Description: Add some commmon git shortcuts
# Reference Source: http://gitready.com/intermediate/2009/02/06/helpful-command-aliases.html
git config --global alias.st status
git config --global alias.ci commit
git config --global alias.br branch
git config --global alias.co checkout
git config --global alias.df diff
git config --global alias.lg log -p
git config --global alias.rb rebase
## Custom Edit to set Sublime as default Text Editor.
git config --global core.editor "subl -n -w"
@toote
Copy link

toote commented Feb 26, 2015

You can add those things to the file ~/.gitconfig directly instead of using git config --global to do so:

[alias]
    st = status
    ci = commit
    update-branch = !git chec....

@toote
Copy link

toote commented Feb 26, 2015

git add -a returns an error for me:

$ git --version
git version 2.2.1
hub version 1.12.1
$ git add -a
error: unknown switch `a'
usage: git add [options] [--] <pathspec>...

@toote
Copy link

toote commented Feb 26, 2015

another (and simpler) way to do the update-branch (that does not touch your local master branch) would be: git fetch; git rebase origin/master

Be very careful with rebasing changes you have already pushed, though!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment