snippetjavascriptTip
Rebase onto another Git branch
Viewed 0 times
ontorebasegitbranchanother
Problem
If you've ever worked on a large project, you might have come across the need to get your branch up-to-date with another branch. Git provides a way to do this using the
In order to perform a rebase, you'll first have to use
If you have merge conflicts or stop to make changes, you can continue the rebase when ready using
git rebase command.In order to perform a rebase, you'll first have to use
git checkout to switch to the branch you want to rebase. Then, you can use git rebase to rebase the current branch onto the target branch.If you have merge conflicts or stop to make changes, you can continue the rebase when ready using
git rebase --continue or abort it using git rebase --abort.Solution
# Syntax:
# git checkout <branch>
# git rebase <base-branch>
git checkout patch-1
git rebase master
# `patch-1` is rebased onto `master`
git checkout patch-2
git fetch origin
# Fetch latest remote branches
git rebase origin/master
# `patch-2` is rebased onto the latest remote `master`If you have merge conflicts or stop to make changes, you can continue the rebase when ready using
git rebase --continue or abort it using git rebase --abort.Code Snippets
# Syntax:
# git checkout <branch>
# git rebase <base-branch>
git checkout patch-1
git rebase master
# `patch-1` is rebased onto `master`
git checkout patch-2
git fetch origin
# Fetch latest remote branches
git rebase origin/master
# `patch-2` is rebased onto the latest remote `master`Context
From 30-seconds-of-code: rebase-onto-branch
Revisions (0)
No revisions yet.