Logo

dev-resources.site

for different kinds of informations.

NOTES: Merge or Rebase

Published at
12/15/2020
Categories
merge
rebase
cheatsheet
git
Author
erinfoox
Categories
4 categories in total
merge
open
rebase
open
cheatsheet
open
git
open
Author
8 person written this
erinfoox
open
NOTES: Merge or Rebase

Recently, I learned that merging a main branch, into your local working branch is a thing 🤯. I was shocked that I just learned about this in my 3+ years of being an engineer. BUT it's never too late to learn. (And take notes for when you forget).

Before, I would always copy/paste my rebase notes from my Notion into my terminal, cross my fingers with selecting the correct "accepting incoming" changes. "blue is you" theories, hope the correct version is added, continued and then force pushed. Sounds scary... but it worked!

From what I understand, merging main into your branch and rebasing from master results in the same goal: The latest most up to date code on your branch with your new feature code.

Merging sounds better to me. At least, it makes more sense, visually. Gelling together all the code, vs dumping it on top, feels better. I needed to learn how to gel instead of dump.

So, let's gel.

Here are my merge and rebase notes. Be aware that these work for me, and may not do exactly what you're hoping for. Chat with your team and do more research when you're learning this.

MERGING

Merging takes the content of the main branch and integrates it with your branch. Only your branch is changing.

Merge Master --> Feature Branch

Let's do it.

$ git checkout [your-branch]
$ git merge main

~~another way~~

$ git merge main [your-branch]
Enter fullscreen mode Exit fullscreen mode

REBASING

Rebasing takes the content of the main branch into a single "patch" and integrates onto your branch.

Apparently, rebasing incorrectly can unintentionally rewrite history. Which sounds really cool, but also like the climax of a bad time travel movie where everything goes bad because they talked to that person they weren't suppose to talk too and now everything is ruined.

For now, I'd like to not time travel until I understand it better.

It moves your entire branch on top of the main branch. It rewrites the project history by making new commits for each commit on your original branch.

Rebase feature branch into master

Let's do it.

$ git pull origin main
$ git checkout [your-branch]
$ git rebase main

--resolve your conflicts-- when you are resolving conflicts *DO NOT COMMIT*

save ****the changes from the conflicts 

$ git add

and then... 

$ git rebase --continue

:wq // or however you have your editor setup 

-- repeat until no more conflicts --
*EVEN if there are no conflicts 

$ git push origin [your-branch] -f
Enter fullscreen mode Exit fullscreen mode

Interactive Rebase

Now this just sound wild. Taking it a step further, interactive rebasing allows altering the commits as they are moved to the new branch. This gives you more control over your branch's commit history. I've heard you use this type of rebase when things are really harry.

Let's do it.

$ git checkout feature
$ git rebase -i master

This will then open the editor and list the commits that are about to be moved. 
This is where you can change the history, to make it look like how you need it. 
Enter fullscreen mode Exit fullscreen mode

Alright. So now we've learned there are 3 options:

  1. Merge

  2. Automation rebase ("regular")

  3. Interactive rebase

Which one should you use? Great question. I'm still figuring that out, but it starts with understanding each of your options, and the situation that you're in. Do you need to rewrite history? Or will a merge be quicker and all you need?

I believe it's best to chat with your team to hear their philosophies and approaches so everyone is on the same page. Hopefully, all y'all are not time traveling at the same time causing madness and talking to that person you're not suppose to talk to that changes the future.

rebase Article's
30 articles in total
Favicon
Understanding Git Rebase Merge: Chronological vs Logical Order and Commit History
Favicon
A Study on Git Rebase
Favicon
Git Rebase and Code Refactoring for VShell Tool
Favicon
Git Merge vs Rebase
Favicon
Como atualizar um repositório 'forkado' com git rebase
Favicon
Why I prefer rebase over merge (and everything else)
Favicon
Step-by-Step Guide to Rebasing Your Branch onto Dev
Favicon
Git update-refs in a nutshell
Favicon
A Guide to Understanding the Nuances of Git Merge and Rebase
Favicon
Git Merge vs. Rebase: Key Differences
Favicon
Rebasing a Branch Created from Another Branch to Main After Squash Merge: A Step-by-Step Guide
Favicon
A Hands-on Guide to Git Rebase & Resolving Conflicts
Favicon
Refactoring and Rebasing
Favicon
Everything you need to know about git rebase
Favicon
git rebase and git revert to fix the broken application.
Favicon
A clean Git history with Git Rebase and Conventional Commits
Favicon
How to use Git rebase to alter previous commits in the project history
Favicon
Git remove file from not last commit
Favicon
Fixing the branch source with git rebase
Favicon
Project Management: Static Analysis Tools
Favicon
Interactive rebase
Favicon
OSD600 - Refactoring My SSG
Favicon
จะทำยังไงดีน้าาาา.. อยากแก้คำผิดใน commit message ที่ผ่านๆ มา
Favicon
GitHub Workflow, Merge and Rebase
Favicon
Rebase and Merge Don't Mix
Favicon
Professional Version Control with Git: Pt 3 – Rebase and Bisect
Favicon
Git Merge vs Rebase
Favicon
Git Rebase and Interactive Rebase
Favicon
Atomic commits will help you git legit.
Favicon
NOTES: Merge or Rebase

Featured ones: