Skip to content

Instantly share code, notes, and snippets.

@innocarpe
Last active September 6, 2019 09:27
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 innocarpe/ef04074b42d665dd2d06e65bb0af66d9 to your computer and use it in GitHub Desktop.
Save innocarpe/ef04074b42d665dd2d06e65bb0af66d9 to your computer and use it in GitHub Desktop.
Rebase remote develop branch when you working on a feature branch
#!/bin/bash
# Rebase remote develop when you are working on a feature branch
# + delete merged remote/local branches
#
# `git rbd` is a abbreviation of `git rebase develop` :-)
#
# This will...
# 1. Commit current changes temporarily if there are uncommitted changes
# 2. Checkout current branch to develop
# 3. Pull remote develop with '--prune' option
# 4. Remove merged branches (Local)
# 5. Checkout current branch to previous one (where you were working on)
# 6. Rebase develop
# 7. Reset temporary commit to restore
#
# Instruction
# 1. Move this file to ~/.gitsh/
# 2. Add directory path($YOUR_HOME_PATH/.gitsh) to environment variable file
# (like ~/.bash_profile or ~/.zshrc)
# (This would be like 'export PATH=${PATH}:/Users/YOUR_HOME_PATH/.gitsh')
# 3. chmod 0755 git-rbd
# 4. Use the command 'git rbd'
UNCOMMITTED_CHANGES=$(git diff HEAD --name-only | wc -l)
if [ $UNCOMMITTED_CHANGES -gt 0 ];
then
git commit -am "__WIP__"
fi
git checkout develop
git pull --prune
git branch --merged | awk '{if($1 != "*" && $1 != "master") print $1}' | xargs git branch -d
git checkout - && git rebase develop
if [ $UNCOMMITTED_CHANGES -gt 0 ];
then
git reset HEAD~1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment