I have this in a script:

set -e;
git checkout --no-track -b "$new_branch";
git rebase "$base";

on occasion, there are conflicts of course, and what happens is that git rebase exits with 1, and so the script aborts/exits early.

So my automated script doesn't work if there are conflicts, which is frequent enough that it defeats the purpose.

My question is, is there some way to suspend the script upon a non-zero exit code, and then resume the script upon a signal or something? Something like this:

git rebase "$base" || suspend --until x;

so in some other terminal I can resolve stuff and then when I am done in the current terminal I could resume? Something like that?


To run the command once, but pause for failure:

if ! git rebase "$base"; then
  read -p "Press ENTER when you think you've fixed it"
  • that is cool, but I think I just need to run the git rebase command just once, and while I am going I use git rebase --continue etc, can I prevent git rebase from being run twice here? – Alexander Mills Sep 25 '18 at 19:29
  • hmmm, well if git rebase succeeds, it just exits with 0. If it fails, it exits with 1. Then we are expected to do git rebase --continue. So I think something like this works: git rebase || { read -p "press enter to try again" }, right? – Alexander Mills Sep 25 '18 at 19:35
  • yeah your most recent edit seems to be the right thing for my use case, thx – Alexander Mills Sep 25 '18 at 19:35
  • yes it does, I am not sure I understand why the two read commands, why not just one read command, is that a typo? And you can explain the git rebase -p? What the -p flag is doing? – Alexander Mills Sep 25 '18 at 19:36
  • Yeah the git rebase -p, was a typo on my part. Oh I see what you are doing, so yeah, yeah if git rebase fails, we do git rebase --continue after making edits – Alexander Mills Sep 25 '18 at 19:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.