Skip to content

Instantly share code, notes, and snippets.

@ibrahimlawal
Last active April 12, 2021 15:20
Show Gist options
  • Save ibrahimlawal/44ce719e59e9c68909e24db844cf599d to your computer and use it in GitHub Desktop.
Save ibrahimlawal/44ce719e59e9c68909e24db844cf599d to your computer and use it in GitHub Desktop.
Git Scripts for speedy delivery

Creating the executable files

Create new files with the names below in a folder that is on your PATH. The sample command below uses the default editor to open such in your default editor. Likely TextEdit.

$ open -e /usr/local/bin/git-mrm /usr/local/bin/git-ddev

Paste the contents respectively.

Make the newly created files executable

$ chmod +x /usr/local/bin/git-mrm /usr/local/bin/git-ddev

Usage

Like every custom git command

$ git-ddev
$ git ddev
$ git-mrm
$ git mrm
# push to dev after merging remote master onto current branch
# Author: @ibrahimlawal
branch_name=$(git symbolic-ref -q HEAD)
branch_name=${branch_name##refs/heads/}
if [ -z "$branch_name" ]; then
echo Not on a branch, deploy aborted && exit 1
fi
if [ $branch_name = "master" ] || [ $branch_name = "dev" ]; then
echo On $branch_name, deploy aborted
exit 1
fi
git checkout master && git fetch && git reset --hard origin/master && git checkout $branch_name && git merge master --log --no-edit && git checkout dev && git fetch && git reset --hard origin/dev && git merge $branch_name --log --no-edit && git push -u origin dev && git checkout $branch_name
# merge master onto current branch after pulling remote master, then push
# Author: @ibrahimlawal
branch_name=$(git symbolic-ref -q HEAD)
branch_name=${branch_name##refs/heads/}
if [ -z "$branch_name" ]; then
echo Not on a branch, merging remote master aborted
exit 1
fi
if [ $branch_name = "master" ]; then
echo On $branch_name, merging remote master aborted
exit 1
fi
git checkout master && git fetch && git reset --hard origin/master && git checkout $branch_name && git merge master --log --no-edit && git push --set-upstream origin $branch_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment