I think I understand git pull
and this is how I explain it in, what I call, "simple terms":
git pull
is about merging a "remote" branch into a "local" branch.Now I want to get the same kind of explanation for git pull --rebase
. I do not want to use such terms as "head", "index", "fetch", "upstream" because these terms / concept only confuse beginners like me. I know that I need to learn these "advanced" concepts and I do it by reading tutorials but for now, as a part of my learning process, I want to understand git pull --rebase
.
ADDED
I think at some point I heard the following explanation. By git pull --rebase
. When we merge, we do it not in a "symmetric" way, as described above. Instead, we first "forget" the changes in the "local" repository and apply only the changes from the "remote" repository. By doing that we basically "copy" the remote repository as it is. After that we apply the changes from the "local" repository on top. However, it is still not clear to me what exactly it means. In particular, what "on top" means.
Git pull rebase is a method of combining your local unpublished changes with the latest published changes on your remote.
Git pull downloads the newest changes from the remote repository and applies the changes to your local repository. Generally, git pull is git fetch and git merge. Rebasing on the other hand can be a replacement for git merge .
The git pull command is used to fetch and download content from a remote repository and immediately update the local repository to match that content. Merging remote upstream changes into your local repository is a common task in Git-based collaboration work flows.
I see two things that could be clarified: You are focusing on the state of a file in the two branches, but a better way to consider what is going on is in terms of the changesets that have occurred. The second issue is that git pull
is shorthand for two operations: git fetch
, and git merge
. Yes, you write that you "don't want to use words like fetch
", but that's not an "advanced concept". If you want to understand what's going on, you need to start there.
git fetch
essentially informs the local repo of changes that it did not know about.
git merge
unifies the newly arrived changes with your local changes.
The catch is that if things have been happening on both repos without synchronization, they may have diverged:
... b--o--o--o--o (remote)
\
x--x--x (local)
The above shows time left to right; the rightmost point is the most recent. So the newly arrived changes are modifications to an older state of the files, the one marked "b".
git pull
, i.e. plain git merge
, will merge the most recent state of the two branches as best as it can.
git pull --rebase
will pretend that your changes were made not to the state marked "b", but to the most current remote state. In other words it will try to rewrite history so that it looks like this:
... b--o--o--o--o (remote)
\
x--x--x (local)
That's the difference. One consequence is that if you don't rebase, the history of your repo contains some states (which you can rewind to in the future, if you want) where the "x" changes were applied but the "o" changes are absent. After rebasing, there is no such place in the repository.
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