DEV Community

Łukasz Sarzyński
Łukasz Sarzyński

Posted on

GIT rebase

Let's imagine that you very hard work on project changes in your changes branch 😏

[master] -> [10ed] "list of option"
[**your changes**] [111a] "list of option" -> [e45f] "addlogin panel" -> [8e69] "add recovery panel"
Enter fullscreen mode Exit fullscreen mode

But somebody update master branch and add new option there.

[master] -> [10ed] "list of option" -> **[6lyer] "add coment"**
[your changes] [111a] "list of option" -> [e45f] "addlogin panel" -> [8e69] "add recovery panel"
Enter fullscreen mode Exit fullscreen mode

Very good for project, but what do you shuld do now? Create new branch basic on new data and start again (manually copy your files)? NO Git have smart solution for it.

git branch "your changes"
git rebase master
Enter fullscreen mode Exit fullscreen mode

Please switch to your changes branch and use git rebase to refreshing data. The effect will be as follows:

[master] -> [10ed] "list of option" -> [6lyer] "add coment"
[your changes] **[222b] "add coment"** -> [e45f] "addlogin panel" -> [8e69] "add recovery panel"
Enter fullscreen mode Exit fullscreen mode

And this is all. You branches get actual data from master branch and you didn't lose your changes

Please focus that after rebase, your changes branch was remove [111a] hash ("list of option"), and now your history was started at new [222b] hash ("add coment")

But please be careful. What is good looking solution for local repository, for foreign repositor it can destroy branch strategy. Please save this sentence:

Do not rebase commits that exist outside your repository and that people may have based work on.

Cheers !

Top comments (0)