xxxxxxxxxx
the rebase command integrates changes from one branch into
another. It is an alternative to the better known "merge"
command. Most visibly, rebase differs from merge by rewriting
the commit history in order to produce a straight,
linear succession of commits.
xxxxxxxxxx
#The branches are like this
A---B---C topic
/
D---E---F---G main
#git rebase <base> <target>
git rebase master topic
#<target> get moved forward on <base>
#NOTE: commits on <target> change their hash
A°--B°--C° topic
/
D---E---F---G main
xxxxxxxxxx
git fetch origin
git checkout your-branch
git rebase develop
Resolve Conflicts (if any):
If there are conflicts during the rebase, Git will pause and ask you to resolve them. Open the conflicted files, resolve the conflicts, and then continue with the rebase:
git rebase --continue
If you want to abort the rebase at any point, you can use:
git rebase --abort
Push the Changes:
After successfully rebasing, force-push your branch to update the remote branch:
git push origin your-branch --force
xxxxxxxxxx
#switch to master
git checkout master
#pull the latest code
git pull
#go back to your branch
git checkout branchName
#finalize
git fetch
git rebase origin
git push #if git push does not work do | git push --force
xxxxxxxxxx
git rebase -i -branch
# opens interactive rebase interface (more instructions needed
# to work with rebase) -i HEAD~3 #this is selecting 3x commits
# from the head (can change based on rebase)
xxxxxxxxxx
git checkout -b child
git commit
git checkout master
git commit
git checkout child
git rebase master
xxxxxxxxxx
Generally, it is an alternative of git merge command. Merge is always a forward changing record. Comparatively, rebase is a compelling history rewriting tool in git. It merges the different commits one by one.