Giter VIP home page Giter VIP logo

gitworkshop-mergerebase's Introduction

Git Workshop || Merge VS. Rebase

Setup

  • Fork and clone this repo.
  • Create a branch from master named merge-main and rebase-main.
git branch merge-main
git branch rebase-main
  • Push the new branches into the remote repo.
git checkout merge-main
git push -u origin merge-main
git checkout rebase-main
git push -u origin rebase-main

Before we get started, check out the current history of commits.

git log --graph --oneline

This is the ideal history we want to achieve.

NOTE: If you do not know the commands you need, I created a little git command cheat sheet at the bottom. Good luck!

Activity One: Merging a Single Branch

  1. Go into your merge-main branch.
  2. Create a new branch named merge-feature-1.
  3. Create some commits on your merge-feature-1 branch.
  4. Push your merge-feature-1 branch into your remote repo.
  5. Create a pull request to merge the merge-main and merge-feature-1 branch.

You can learn how to create a pull request from here

  1. Review and merge your changes.
  2. Pull the changes on merge-main.
  3. Check out your commit history.

Activity Two: Working with Multiple Branches

  1. Go into your merge-main branch.
  2. This time create two new branches: merge-feature-2 and merge-feature-3.
  3. Create some commits on your merge-feature-2 branch.
  4. Push your merge-feature-2 branch into your remote repo.
  5. Create a pull request to merge the merge-main and merge-feature-2 branch.
  6. Review and merge your changes.
  7. Pull the changes on merge-main.
  8. Check out the commit history of your merge-main branch.
  9. Go back into your merge-main branch.
  10. Create a new branch named merge-feature-4.
  11. Create some commits on your merge-feature-3 and merge-feature-4 branch.
  12. Push your merge-feature-3 and merge-feature-4 branch into your remote repo.
  13. Create a pull request to merge the merge-main and merge-feature-3 and merge-feature-4 branch.
  14. Review and merge your changes.
  15. Pull the changes on merge-main.
  16. Check out the commit history of your merge-main branch.

Do you notice the difference in the commit history when you're working with a single branch at a time and working with multiple branch at the same time?

Activity Three: Using Rebase

How do we keep an organize history while working with multiple branches? The answer is we rebase!

We're going to follow similar steps that we took during activity two except we will rebase our branch before merging it into our main branch

  1. Go into your rebase-main branch.
  2. This time create two new branches: rebase-feature-1 and rebase-feature-2.
  3. Create some commits on your rebase-feature-1 branch.

Your branch is currently based on the most recent commit of master so rebasing will not do anything.

  1. Push your rebase-feature-1 branch into your remote repo.
  2. Create a pull request to merge the rebase-main and rebase-feature-1 branch.
  3. Review and merge your changes.
  4. Pull the changes on rebase-main.
  5. Check out the commit history of your rebase-main branch.

So far everything should look very similar to activity 2, but that is about to change.

  1. Go back into your rebase-main branch.
  2. Create a new branch named rebase-feature-3.
  3. Create some commits on your rebase-feature-2 and rebase-feature-3 branch.
  4. Rebase your rebase-feature-2 branch onto rebase-main.
  5. Push your rebase-feature-2 branch into your remote repo.
  6. Create a pull request to merge the rebase-main and rebase-feature-2.
  7. Review and merge your changes.
  8. Pull the changes on rebase-main.
  9. Before we rebase rebase-feature-3, check out the commit history of rebase-feature-3.
  10. Rebase your rebase-feature-3 branch onto master.

Check the commit history or rebase-feature-3, does it look different?

  1. Push your rebase-feature-3 branch into your remote repo.
  2. Create a pull request to merge the rebase-main and rebase-feature-3.
  3. Review and merge your changes.
  4. Pull the changes on rebase-main.
  5. Check out the commit history of your rebase-main branch.

Compare the history of commits on merge-main vs. rebase-main, what do you notice?

Git Command Cheat Sheet

Command Results
git branch [branch name] Creates a new branch.
git checkout [branch name] Switches to the branch.
git checkout -b [branch name] Creates a new branch and switches to it.
git add . Adds all changes in the repo to the staging area.
git commit -m [log message] Commits all the changes in the staging area.
git pull [branch name] Updates your local repo based on your remote repo.
git push -u origin [branch name] Pushes your local branch for the first time into the remote repo.
git rebase master [branch name] Moves the starting point of your branch to the most recent commit on master.
git log --graph --oneline Visually displays your commit history

gitworkshop-mergerebase's People

Contributors

wf-home avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.