Giter Club home page Giter Club logo

fun-git's Introduction

Hi. I'm Keziyah.

  • ๐Ÿ‘ฉ๐Ÿพโ€๐Ÿ’ป software engineer
  • ๐Ÿคซ introvert
  • ๐Ÿ’ƒ๐Ÿพ shuffle dancer
  • ๐Ÿ’œ she/her, they/them

fun-git's People

Contributors

keziyah avatar

Watchers

 avatar  avatar

fun-git's Issues

rebasing

In which Keziyah learns what a rebase is, and how it can get her out of this situation:

I'm working on a feature branch, my-feature-1, and while it's waiting to be merged, I need to open another branch that depends on it. So while in my-feature, I git checkout -b my-feature-2.

I work on my part 2 branch, meanwhile my-feature has since been merged, as well as a few other branches that other people have worked on. How do I get my-feature-2 into master without messing things up?

What is rebasing

Rebasing and merging have the same end goal. Taking feature branches and integrating them into master. But they do it in different ways. Merges create a new merge commit on master.
Screen Shot 2020-02-04 at 11 11 54 AM

Rebasing takes you feature commits and moves them on top of the master branch. It rewrites history by erasing your feature branch commits and just putting your feature on top of master.
rebase gif

Source

So, like, what do I do

According to this Stack Overflow answer, I should do something like this:

  1. After opening a new branch my-feature-2 from my-feature-1
  2. Anytime my-feature-1 changes during code review, rebase my-feature-2 on it.
    ... commit something onto my-feature-1 ... git checkout my-feature-2 git rebase my-feature-1
    This will take my feature 2 commits and put them on top of what i've done from feature 1, making my feature 2 commit history appear to start right after my latest changes to feature 1.
  3. When feature 1 is merged, rebase feature 1 onto it again:
    git checkout master git pull origin master git checkout feature-2 git rebase --onto master feature-1 feature-2
    This makes it so that my feature-2 branch is branched off master.

Task

I'm going to try this.

  1. Create a feature-1 branch, make some commits
  2. Create a feature-2 branch off feature 1
  3. Create other branches and merge them into master before feature-1 is merged
  4. Merge feature-1 and make it so that feature-2 is branched off master

Results

  1. I created 4 branches: features 1-4. Feature 2 is branched off Feature 1.
  2. I merged feature-3 and feature-4 into master.
  3. I went into feature-1 and did git merge master
  4. Since feature-1 has changed, I have to rebase feature-2 on it. So I checked out feature-2 and did git-rebase feature-1
    Now my feature-2 looks like it began after the latest master merge into feature-1.

Before rebasing:

Feature 2 history:
Screen Shot 2020-02-04 at 11 54 16 AM
Feature 1 history:
Screen Shot 2020-02-04 at 11 55 29 AM

After rebasing:

Feature 2 history
Screen Shot 2020-02-04 at 12 02 14 PM

Then I merged feature-1 into master.

Now to clean up the difference between feature-2 and master. There are more changed files than necessary. The ReadMe, for example, is exactly how it is in master. That's why we need to rebase.
So while in feature-2, I did git rebase --onto master feature-1 feature-2

Changed file list before rebase:
Screen Shot 2020-02-04 at 12 07 53 PM

After rebase:
Ok, never mind, it didn't work. The changed files in feature-2 are still the same.

Second try

  1. Created 3 branches. f-1, f-2, and f-3. f-2 depends on f-1.
  2. Merged f-3 into master.
  3. did git rebase master f-1 while in branch f-1. so that my f-1 commits come after the latest master.
  4. Merged f-1 into master
  5. git rebase master f-1
  6. git rebase --onto feature1 f-1@{1} f-2
    Source
    I think this worked better. Woohoo!

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.