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
#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
# Suppose you have a feature branch called 'feature-branch' and you want to rebase it onto the 'main' branch.
# 1. Make sure you are on the 'feature-branch'
git checkout feature-branch
# 2. Fetch the latest changes from the 'main' branch
git fetch
# 3. Start the rebase
git rebase main
# During the rebase, you might encounter conflicts if there are changes that conflict with your 'feature-branch'. Git will guide you through resolving these conflicts.
# 4. If conflicts occurred, resolve them, add the resolved files, and continue with the rebase
# Repeat these steps for each conflicting file
git add <file-name>
git rebase --continue
# 5. Once the rebase is complete, push the rebased branch to remote (if it was already pushed before)
git push origin feature-branch --force
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
#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 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.