DEV Community

Łukasz Sarzyński
Łukasz Sarzyński

Posted on

2 2

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 !

AWS Q Developer image

Your AI Code Assistant

Generate and update README files, create data-flow diagrams, and keep your project fully documented. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay