8

Could anyone explain this with keeping even the remote repositories in mind?

1
  • 1
    There is no git commit --rebase; did you mean git pull --rebase? Or, git svn dcommit --no-rebase? (missed the git-svn tag at first) Commented Apr 27, 2012 at 5:49

2 Answers 2

10

git pull --rebase is the way to go when you want to bring your development branch up to date - those branches are usually not published to others (except maybe for having a look at it) so rewriting history is not a problem and you really don't want merges etc in such a branch.

git merge performs a merge; see the manpage for details - the comand has tons of options which would be too much to explain here.

git rebase performs a rebase, i.e. it rewrites history. It will take your commits up to the point where they diverge from the other branch, remove them temporarily, apply the missing commits from the other branch and then re-apply your commits. git rebase also has an interactive mode where you can remove/modify/combine(squash) certain commits.

Have a look at http://learn.github.com/p/rebasing.html for some nice graphs on how rebases work.

Sign up to request clarification or add additional context in comments.

1 Comment

Note: git 2.8 (March 2016) will allow for a git pull --rebase=interactive command. See stackoverflow.com/a/29717607/6309.
7

git rebase allows you to detach a branch from the point it has diverged, and re-plug it on top of the other branch. git merge is instead simply merging the changes from another branch in the current branch, without history re-plugging.

If there are no conflicts, the result is identical between merge and rebase, but the history is different:

(merge branch on master):
master    --A--B--C--E
                   /
branch          --D

(rebase branch onto master):
master     --A--B--C--D'

In first case the merge creates the branch branch is merged into master, leading to creation of a merge commit, E. In the second case, D is simply re-plugged onto master, creating anther commit, D'.

git pull --rebase will fetch the changes from a remote, and rebase (re-plug) your changes on top of it. It will literally record the changes you made that are not on the remote, and replay them starting from the last change that it just fetched.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.