Last active
September 7, 2018 18:36
-
-
Save srevenant/ba2d8c8fb57a762581f053c848a0f4f6 to your computer and use it in GitHub Desktop.
fast-forward git bash helpers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# When working on a project with multiple developers master will get ahead of your work. | |
# To come in sync should you rebase? merge? what is a fast-forward? Lots of discussion | |
# is available on this, here are a few: | |
# https://hackernoon.com/git-merge-vs-rebase-whats-the-diff-76413c117333 | |
# https://www.atlassian.com/git/tutorials/merging-vs-rebasing | |
# | |
# I prefer a merge/fast-forward, rather than rebase. These helpers assist in that process. | |
# LMK your thoughts and if you know of a better way! Enjoy! | |
# helper functions | |
get_branch() { | |
local branch=$(git branch |grep '^\*'|awk '{print $2}') | |
if [ "$branch" = "" ]; then | |
echo "Cannot determine branch" 1>&2 | |
return 1 | |
fi | |
echo $branch | |
return 0 | |
} | |
cmdecho() { | |
echo ">>> $@" | |
"$@" | |
return $? | |
} | |
# fast-forward local master against remote master, then fast-forward local branch against local master | |
# then checkpoint back to remote (unless there are merge conflicts) | |
ffmaster() { | |
local branch=$(get_branch) && | |
cmdecho git checkout master && | |
cmdecho git pull && | |
cmdecho git checkout $branch && | |
cmdecho git merge master | |
# cmdecho git push origin $branch | |
} | |
# fast-forward local branch against remote master (does not fast forward local master) | |
# then checkpoint back to remote (unless there are merge conflicts) | |
ffbranch() { | |
branch=$(get_branch) | |
if [ "$branch" = "master" ]; then | |
cmdecho git pull | |
else | |
cmdecho git pull origin master | |
# cmdecho git push origin $branch | |
fi | |
} | |
# commit and push everything added (you do this first) with a comment from the CLI | |
compush() { | |
branch=$(get_branch) || return 1 | |
echo "Branch: $branch" | |
if [ "$*" = "" ]; then | |
echo "No comment? try: 'compush this is a comment'" | |
return 1 | |
fi | |
echo -n "Commiting to branch $branch, [ok]" | |
read | |
commit $@ && git push origin $branch | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment