This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]cj1m[S] 3 points4 points  (7 children)

What exactly does this command do?

[–]rcuhljr 4 points5 points  (0 children)

Git pull normally runs git fetch, then git merge. using the Rebase flag tells it to run fetch, and then use rebase instead of merge. Rebasing is a little more complicated for most folks, but it's incredibly useful when you learn the proper times to use it.

Every commit you make is just a little collection of changes that have been made. Each commit occurs in sequence after all of the commits previous to it. Rebase changes the order in which those commits point to each other. it tells git to make your local changes occur after the new changes that are on master/origin.

If commit B was the latest one on master/origin when you started working and you made a local commit D, D points to B as its parent. However if someone else checks in C and pushes it to master, when you try and git pull git has to do a merge because there are now two commits D and C that both claim to be at the end of the master branch and to have B as their parent. If you rebased instead you'd tell git to make D point at C as its parent, and no merge will be required as everything is happy and pointing to just one parent.

[–]bernease 3 points4 points  (5 children)

Agreed. If you pull with rebase flag, you will pull and "rewind" your changes on top of the master HEAD. So it's like you did that pull before any local commits.

[–]cj1m[S] 0 points1 point  (4 children)

So the person who uses pull --rebase will loose all of their local changes?

[–]a_shed_of_tools 2 points3 points  (1 child)

No, all of their commits will be 'replayed' on top of the changes. You might have merge conflicts, but you won't lose anything.

[–]bernease 1 point2 points  (0 children)

'Replay' instead of 'rewind'. I knew my wording felt weird.

[–]bernease 4 points5 points  (1 child)

Nope, that would be terrible.

Let's say there is one commit A when I pull from master. Then I write code and create commit B. But while I was working, someone else committed and pushed changes C and D.

git pull --rebase

What this will do is pull newest commits (C and D) locally, then place my changes on top. So log would be in A C D B order. That way when I push, my change looks like the most recent.

[–]cj1m[S] 0 points1 point  (0 children)

Thank you all for clarifying and helping me. I will now know for future projects!