Skip to content

Instantly share code, notes, and snippets.

@benekastah
Last active August 29, 2015 14:20
Show Gist options
  • Select an option

  • Save benekastah/f7420c74ffe6e68bb280 to your computer and use it in GitHub Desktop.

Select an option

Save benekastah/f7420c74ffe6e68bb280 to your computer and use it in GitHub Desktop.
Git babysit - remind yourself to do the things you always forget before pushing
[alias]
babysit = !git-babysit
#!/usr/bin/env bash
this-branch() {
git rev-parse --abbrev-ref HEAD
}
list-item() {
echo "$1 (y/n/d) "
read yn
case "$yn" in
y|Y|yes)
;;
n|N|q|Q|no)
exit 1
;;
d|D)
git diff origin/master...HEAD
list-item "$1"
;;
*)
echo "Invalid response: $yn"
list-item "$1"
;;
esac
}
show-checklist() {
list-item 'Did you thoroughly fix the entire problem?'
list-item 'Is this the simplest/smallest set of changes that can be made?'
list-item 'Can you say there no areas that need further comments?'
list-item 'Where possible, did you remove comments by making the code clearer?'
list-item 'Have you assessed the risk these changes pose and explored less risky options?'
list-item 'Did you list out potential edge cases and test them?'
list-item 'Have you thoroughly tested all branches of your code?'
list-item 'Have you written tests where necessary?'
list-item 'Have you run the tests?'
push_cmd="git push -u origin \"$(this-branch)\""
list-item "Automatically push ($push_cmd)?"
eval "$push_cmd"
}
show-checklist
@benekastah

Copy link
Copy Markdown
Author

Here's the workflow I use with this:

  1. Make and commit changes
  2. Before pushing, run git babysit. Uncommitted changes don't show up in the diff in git babysit so ensure all the things you want to push are already committed for best results.
  3. If you can answer yes to all the questions, you are good to go. At the end, git babysit will offer to push for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment