Skip to content

Instantly share code, notes, and snippets.

@arukompas
Last active March 31, 2019 11:49
Show Gist options
  • Save arukompas/b9e2d02ae92e0122462b509b029ee893 to your computer and use it in GitHub Desktop.
Save arukompas/b9e2d02ae92e0122462b509b029ee893 to your computer and use it in GitHub Desktop.
Git aliases
# Display the status of the current branch
alias gs="git status"
# Display a list of branches on your local machine
alias gb="git branch"
# Add all files to the staging area
alias ga="git add ."
# Commit staged files with a message
alias gc="git commit -m"
# Add all files to the staging area and commit them with a message
alias gac="git add . && git commit -m"
# Checkout to a new branch
alias gnew="git checkout -b"
### functions can also be called from the command line,
### which is kind of like an alias, but with advanced capabilities
# Pull the latest changes from a remote branch
# (current by default, or you can speficy which specific branch you'd like to pull from)
function gpull () {
if [ -z "$1" ]
then
git pull origin `git rev-parse --abbrev-ref HEAD`
else
git pull origin $1
fi
}
# Push the local changes to the remote branch
# (current branch by default, or you can specify a different one)
function gpush () {
if [ -z "$1" ]
then
git push origin `git rev-parse --abbrev-ref HEAD`
else
git push origin $1
fi
}
# Checkout to a different branch and pull the latest changes from it automatically
function ch() { git checkout $1; gpull; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment