DEV Community

Rémi Lavedrine
Rémi Lavedrine

Posted on • Edited on

The Git Rebase Workflow

Hi everyone,

Looking for something totally different on the internet, I got to see that video about a "Git Rebase" workflow that is different from the "standard" "Git Merge/Pull Request" workflow.
The developer on the video is making a pretty good job at explaining clearly why it is interesting, and how it is working in practice.

That looks pretty interesting as indeed a Git tree can become really huge when using the Pull Request/Merge workflow.

I want to have your feedback, feeling about that Git workflow.

Do you used it on your project? Wether you are working alone on your project or you are collaborating with other developers.

I would be happy to have your feedback about what you feel about the Git workflow.

I used it quickly on a test repo to see how it is working and it is petty interesting.


Try it

If you want to test it, you can use the following script to have a local git folder ready so you can experiment the git rebase workflow :

#!/bin/zsh

git branch "feature/1"
git checkout "feature/1"

echo "Feature 1 : " >> README.md
echo "1" >> README.md
git commit -a -m "Feature 1 : 1"

echo "2" >> README.md
git commit -a -m "Feature 1 : 2"

echo "3" >> README.md
git commit -a -m "Feature 1 : 3"

git checkout "master"

echo "Master" >> README.md
echo "1" >> README.md

git commit -a -m "Master 1 : 1"
Enter fullscreen mode Exit fullscreen mode

Git Rebase Workflow

Then, to use the Git Rebase workflow, you can try :

# Checkout the Feature branch.
git checkout feature/1

# Rebase the Feature branch onto "master" the interactive way.
git rebase -i master

#Resolve conflicts

# Continue rebasing now that the conflicts are resolved.
# Squash your commits into the first one and reword the first commit to explain all the changes from the 3 commits modifications.
git rebase --continue

# Checkout the "master" branch.
git checkout master

# Rebase the master branch onto "master".
git rebase feature/1

# Delete the Feature branch.
git branch -D feature/1
Enter fullscreen mode Exit fullscreen mode

Git Merge (Squash Commits) Workflow

If you want to have the same result using git merge, you can try :

# Move to the master branch.
git checkout master

# Merge the "feature/1" branch and squash the commits.
git merge --squash feature/1

#Resolve conflicts

# Commit your changes and add a single commit message for all your commits.
# You can omit the "-m" to have a template popping up based on your previous commit messages.
git commit -m "Feature 1 : 1, 2 et 3"

# Delete the "feature/1" branch that is no longer needed.
git branch -D feature/1
Enter fullscreen mode Exit fullscreen mode

Cheers.


Video produced by Wild & Secure, your consulting firm to all things security and real estate.
If you want to receive weekly quality content about security, subscribe to our newsletter on our website.

Top comments (11)

Collapse
 
linden profile image
Anders Lindén

This guide gives some good examples to start with
git-rebase.io/

Collapse
 
shostarsson profile image
Rémi Lavedrine

Thank you for sharing that link.
That is indeed very interesting. I started reading it, but I am going to spend some more time reading it later. :-)

Collapse
 
juancarlospaco profile image
Juan Carlos

I just do git pull --rebase --force

Collapse
 
shostarsson profile image
Rémi Lavedrine

Interesting. :-D

Collapse
 
seokjeon profile image
Se-ok Jeon

Thx for this! This is really what I wanted. Helped A LOT.
Can I translate in Korean this article? If you don't mind, I wanna share this awesome information in Korean. Surely, There will be a link directing to this original one.

Collapse
 
shostarsson profile image
Rémi Lavedrine

Hello,

Yes feel free to translate it. Link your article to the original one. :-)

Collapse
 
jessekphillips profile image
Jesse Phillips

Basically you want to only merge into mainline, rebase your working branch to get the latest from mainline.

Note this advice holds true if you have multiple mainlines. Merge across mainlines.

Collapse
 
vlasales profile image
Vlastimil Pospichal

rebase master->feature
merge feature->master

Collapse
 
hiigami profile image
hiigami

I think this is oneflow workflow with option 1.
endoflineblog.com/oneflow-a-git-br...

Collapse
 
myerschris78 profile image
Chris Myers

This is the article that helped me learn about rebase. I still use it today.

gist.github.com/alper/846c187892fe...

Collapse
 
shostarsson profile image
Rémi Lavedrine

Thanks for sharing. 👍