2

I'm trying to write an alias up for git which does the following

  1. Stash changes to current branch foo
  2. Checkout master
  3. Fetch/Pull
  4. Checkout foo
  5. git merge master
  6. Restore stashed changes
up = !git stash save masterupdate && git checkout master && git fetch && git pull && git checkout @{-1} && git merge master && git stash pop stash^{/masterupdate}

This works unless there is a merge conflict that needs to be resolved. In such cases, it stops at the conflict step and I need to manually apply the stash.

  • How can I make it so upon resolving the merge conflict the rest of the chained commands would continue as normal again?
  • Is the only option to make a second alias for this case?
  • Can the stash messages be squelched in the case of no change?

My workflow involves making pull requests which then get reviewed by other team members, rebasing is not an option as it would destroy their comments

Paul S.
  • 64,864
  • 9
  • 122
  • 138
  • Consider the following approch: check if merge can be done auto without conflict, only then start it - otherwise prompt message about the conflict to the user and don't start your flow.. Github act like this in pull request. Check this:http://stackoverflow.com/questions/6335717/can-git-tell-me-if-a-merge-will-conflict-without-actually-merging – ItayB Apr 18 '16 at 20:11

1 Answers1

0

As far as the question:

How can I make it so upon resolving the merge conflict the rest of the chained commands would continue as normal again?

You can't. Because the merge fails it stops the shell executing of your cli.

You could write a shell script that does the same thing with some checks to see if you ran the script a 2nd/3rd time so it would skip straight to your git stash pop stash^{/masterupdate} If you name the script git-something, you can actually run your command like git something and you could create an alias calling git something

Peter van der Does
  • 14,018
  • 4
  • 38
  • 42