Does anyone know what is the difference? Seems to me, it is the same. But when I run it, it didn't do the same thing:
git rebase origin/branch
- ok rebases from remote branch
git rebase origin branch
- makes conflicts
if you want to rebase a branch based on remote master branch, git rebase origin/master is not enough, it will not get new commits directly from origin/master. You need to git fetch before git rebase origin/master . or you can use another way to rebase a branch. then, your branch is updated to newest commits.
What is git rebase? From a content perspective, rebasing is changing the base of your branch from one commit to another making it appear as if you'd created your branch from a different commit. Internally, Git accomplishes this by creating new commits and applying them to the specified base.
Explanation. The origin is the remote branch which is the primary working directory of a project. All other branches merge into this branch. branchname is just another branch, or a copy of the original branch, where developers code independently.
Git Merge Vs Git Rebase: Git merge is a command that allows you to merge branches from Git. Git rebase is a command that allows developers to integrate changes from one branch to another. In Git Merge logs will be showing the complete history of the merging of commits.
@Mar's answer is right and perfectly solved this question, just add one comment.
if you want to rebase a branch based on remote master branch, git rebase origin/master
is not enough, it will not get new commits directly from origin/master. You need to git fetch
before 'git rebase origin/master'.
or you can use another way to rebase a branch.
git checkout master
git pull origin master
git checkout {your branch}
git rebase origin/master
then, your branch is updated to newest commits.
git rebase <upstream> <branch>
is equal to
git checkout <branch> git rebase <upstream>
By default <branch>
is HEAD
.
[1] https://www.kernel.org/pub/software/scm/git/docs/git-rebase.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With