patternbashgitMinor
Git script that fast forward merges and deletes the old branch
Viewed 0 times
scriptfastforwardthemergesdeletesthatgitandbranch
Problem
This script fast forward merges a branch and then deletes the old one. I normally run it like this:
Here's a link to the gist.
Is there anything wrong with this? My biggest fear is I could run this script with a typo and end up deleting a branch without merging first.
git m master featureHere's a link to the gist.
#!/bin/bash -x
set -e
#by naming this git-m and putting it in your PATH, git will be able to run it when you type "git m ..."
if [ "$#" -ne 2 ]
then
echo "Wrong number of arguments. Should be 2, was $#";
exit 1;
fi
git checkout $1;
git merge --ff-only $2;
git branch -d $2;Is there anything wrong with this? My biggest fear is I could run this script with a typo and end up deleting a branch without merging first.
Solution
The order of the arguments is backwards, I think. Compare against
Synopsis
Description
If `
git-rebase(1):Synopsis
git rebase [] []Description
If `
is specified, git rebase will perform an automatic git checkout before doing anything else. Otherwise it remains on the current branch.
The git-rebase order is also better since the git checkout can be considered optional. You should probably make yours optional as well.
The help message needs to be much more informative about what the command does and how to use it. Git is hard enough to use as it is.
Accidental branch deletion is unlikely to be tragic, since you used -d and not -D`.Context
StackExchange Code Review Q#55566, answer score: 3
Revisions (0)
No revisions yet.