Skip to content

Instantly share code, notes, and snippets.

@himanshuteotia
Last active August 18, 2021 10:23
Show Gist options
  • Save himanshuteotia/75dad0c9ec337af4ff8690b5650fac02 to your computer and use it in GitHub Desktop.
Save himanshuteotia/75dad0c9ec337af4ff8690b5650fac02 to your computer and use it in GitHub Desktop.
Create PR for hot fixes
You can follow this steps;
1. checkout to stage and ensure that you have the latest code
2. checkout to live and ensure you have the latest code
3. create a new branch from live , you can call it hot-fix-<simple name of the changes> e.g. "hot-fix-user-rb-api"
4. cherry-pick each of the commits you want from stage into the new branch you created (you can get the commit ids from the PR that contains the changes you want to hot fix)
5. Create a PR from the hot-fix branch -> live
@himanshuteotia
Copy link
Author

git fetch upstream
git co upstream/stage
git co -b api-key-update
git cherry-pick 61fdc8f
git push origin api-key-update

@himanshuteotia
Copy link
Author

Using cherry-pick
git cherry-pick allows you to pick any commits you made in any branch to any other branch. In your case you can simply checkout master branch and then cherry-pick all the commits from any branch that you wish (cherry-pick supports ranges so you can specify start and end commit instead of listing all the commits).

This way you can control the way your commits will appear in the desired branch.

For example:

git cherry-pick ebe6942..905e279

Find the range of commits you wish to re-add to your branch.

then use cherry-pick to add them back to the branch

git cherry-pick start..end

If you wish to include the start commit as well add the ^

This will result in a cherry-pick of the start commit included as well

git cherry-pick start^..end
How to find first commit of branch?
git log

print out the latest commit (first one) of the given branch

git log --oneline | tail -1
merge-base
Use the merge-base command to find where the branch was split from the original branch:

git merge-base A B

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