Skip to content

Instantly share code, notes, and snippets.

@hellofromtonya hellofromtonya/.gitconfig
Last active Dec 27, 2019

Embed
What would you like to do?
Git Productive - Global .gitconfig aliases
[alias]
# Opens the Atom editor.
atom = ! atom
# ===================================
# Viewing history
# ===================================
# Shows a graphical log.
logone = log --oneline --decorate --all --graph
# Shows the log for the last commit.
loglast = show --summary
# Less verbose status.
st = status --short --branch
# ===================================
# Staging
# ===================================
stagea = "!f() { \
clear; \
git add -A; \
git st; \
echo 'Staging all the working changes....'; \
}; f"
unstagea = "!f() { \
clear; \
git reset HEAD --; \
git st; \
echo 'Unstaging all the changes by moving them back to the working directory....'; \
}; f"
unstage = "!f() { \
clear; \
git reset HEAD ${1-'--'}; \
git st; \
echo 'Unstaging change(s) by moving it(them) back into the working directory....'; \
}; f"
# ===================================
# Commits
# ===================================
# Commits everything in the working and staging ares.
# When a commit message is not provided, it pops the editor open.
commita = "!f() { \
git add -A; \
commit_msg=$1; \
if [[ $commit_msg != '' ]]; \
then git commit -m \"$commit_msg\"; \
else git commit; \
fi; \
clear; \
git st; \
git loglast; \
echo 'Committed all changes....'; \
}; f"
# Commits everything in the working and staging ares.
# When a commit message is not provided, it pops the editor open.
commitanv = "!f() { \
git add -A; \
commit_msg=$1; \
if [[ $commit_msg != '' ]]; \
then git commit --no-verify -m \"$commit_msg\"; \
else git commit --no-verify; \
fi; \
clear; \
git st; \
git loglast; \
echo 'Committed all changes....'; \
}; f"
# Uncommits the last commit, throwing away the commit and moving the changes
# back into the working directory.
uncommit = "!f() { \
git reset HEAD^ -q; \
clear; \
git st; \
echo 'Uncommitted the last commit, moving the changes back into your working directory....'; \
}; f"
# Pops open your text editor, where you can reword the last commit message.
# Any WIP changes are stashed and then reapplied after you get done changing the message.
reword = "!f() { \
git stash; \
git commit --amend; \
git stash pop; \
clear; \
git loglast; \
echo 'Fixed the commit message....'; \
}; f"
# Adds all of the new changes (WIP) in both your working and staging areas to the last commit.
# It keeps the commit message. Therefore, no commit message is needed.
addto = "!f() { \
git add -A; \
git commit --amend --no-edit; \
clear; \
git loglast; \
echo 'Added all working and staged changes (WIP) to the last commit....'; \
}; f"
# Rolls everything back to the last commit. CAUTION: this command deletes
# all of the changes you've made.
rollback = "!f() { \
git unstage; \
git checkout -- .; \
git clean -fd; \
clear; \
git st; \
echo 'Rolled back to the last commit....'; \
}; f"
# ===================================
# Branches
# ===================================
# Creates a new branch and checks it out.
newbranch = checkout -b
# Deletes both the local and remote branch.
deletebranch = "!f() { \
name=$1; \
if [[ $name == '' ]]; \
then echo 'Whoops, you forgot to give me the branch name.'; exit -1; \
fi; \
clear; \
git branch -D $name; \
echo \"Deleted the local ${name} branch.\"; \
git branch; \
git push origin --delete $name; \
echo \"Deleted the remote ${name} branch.\"; \
}; f"
# Renames the current branch.
rename = "!f() { \
new_name=$1; \
if [[ $new_name == '' ]]; \
then echo 'Whoops, you forgot to give me the new branch name.'; exit -1; \
fi; \
clear; \
git branch -m $new_name; \
echo \"Renamed the current branch to ${new_name}.\"; \
git branch; \
}; f"
@hellofromtonya

This comment has been minimized.

Copy link
Owner Author

hellofromtonya commented May 21, 2018

This global .gitconfig file is from the hands-on coding lab, Git Productive on Know the Code.

In this lab, we are taking confusing and time-consuming tasks, wrapping them up in scripts, and building a simple alias command to automate the work we do every single day in our workflow.

These aliases have been tested on Windows and Mac.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.