Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: difference "git rebase origin/branch" VS "git rebase origin branch"

Tags:

git

rebase

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

like image 763
Adam Avatar asked Mar 20 '15 10:03

Adam


People also ask

Can I rebase on Origin branch?

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 does git rebase origin do?

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.

What is git branch origin?

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.

What is the difference between git rebase?

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.


2 Answers

@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.

  1. switch to master git checkout master
  2. git pull origin master
  3. switch back to your own branch git checkout {your branch}
  4. git rebase origin/master

then, your branch is updated to newest commits.

like image 194
Xiongmin LIN Avatar answered Sep 26 '22 16:09

Xiongmin LIN


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

like image 40
svlasov Avatar answered Sep 26 '22 16:09

svlasov