What is GIT Rebase
Introduction to Rebase
Git's rebase command is difficult to understand for beginners and the description of the man page doesn't help in the least:
git-rebase - Forward-port local commits to the updated upstream head
Uh, please? That might help if you know how Git works. But not in the slightest if you're just starting out with Git. Thanks to Travis Swicegood, we have a better metaphor:
A hatchet. Rebase helps break up commits and slice them up in the way you want them to be served, and places them exactly where you think they belong. With the command, you can actually rewrite the history of your repository, be it rearranging commits, merging them into larger commits, or ignoring commits if you so choose.
Why is that helpful? One of the most common use cases is working on a specific feature or bug in a separate branch. Instead of creating ugly merge commits for every change that gets pushed into the master branch, you could create a big change and let Rebase handle it all. Another common case for rebase is maintaining your own changes for a project. With merges the repository history is mixed up with upstream commits and own commits. Rebase prevents this and thus keeps the repository in a balanced state. The end of Git for Computer Scientists or James Bowes ’contribution on the topic shows how this looks graphically.
A simple example shows how Rebase works. I create a new branch for my feature, develop it and commit my changes.$ git checkout -b newfeature Switched to a new branch "newfeature" [.. changed some files, made a few commits ..] $ git checkout master Switched to branch "master" [.. changed one file, committed ..]
The history in the repository looks like this (screenshot from gitx):
Now I want to bring the changes back to the master branch. From there I could merge the changes. If I did that, the commit history would look like this:
Our history would look like this instead:
You can see how everything locks up much cleaner and more compact. The changes were relatively easy, Merge was really easy and didn't require any work. Future tips will cover solving merge problems, the different merge algorithms available and of course the interactive mode of Rebase. This post first explains the basics of the command itself. If you know useful tricks that you can do with Rebase, submit a tip!
- What are the best prepaid cellular providers
- What does per second squared?
- What is the correct spelling for Israel
- What is the most diverse sport
- What are the achievements of America
- Should Japan accept Uyghurs
- How to properly breed Betta fish
- How does a soup stone work
- Is learning Arduino useful for kids
- How do you avoid distractions while writing
- How did the media brainwash you
- What is it like to defend a thesis?
- What does 2 people mean
- Is Jatayu a vulture or an eagle
- You should keep your goals a secret
- What does Oh Snap
- What's the next raid
- What are some big predators
- What does sober life mean
- How can one commit suicide by overdosing?
- Light interacts with antimatter
- What are less than deadly weapons?
- Why don't school dress codes allow Baerte
- How can I see Babumoshai Bandookbaaz