Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7079561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:41:13+00:00 2026-05-28T06:41:13+00:00

I have a git branch that I have been working on called feature1 with

  • 0

I have a git branch that I have been working on called feature1 with committed code. I realized that I would like to split up some of the new functionality into a new branch called feature2 and remove that functionality from feature1 to keep a clear separation between the features.

I have been trying to figure out a good way to accomplish this so that I can later bring feature2 and/or feature1 into master.

The solution I thought of is to create feature2 branch based off feature1, then delete the feature2 related code from feature1. My fear with doing this is that if feature2 gets merged into master first, then feature1 got merged after, would the “deletes” remove feature2 code from master?

Is there a better way I should do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:41:14+00:00Added an answer on May 28, 2026 at 6:41 am

    Try this:

     git branch original-tip
     git branch feature2
     git checkout -b feature1
    
     git rebase -i HEAD~5 # replace 5 with the number of commits to go back
                          # before any of this work occurred
    

    Now mark all the commits with “edit” and erase any lines that have no relevant work to feature 1. Save and exit. Now you will be prompted to edit these commits. Add whatever you need and stage it and then

     git rebase --continue
    

    Repeat this process until the rebase is complete.

     git checkout feature2
    

    Apply the same steps as before for feature2. After this you will have your 2 separate features and a branch pointing to where you had them both together.

    To add:

    There is another way to accomplish this.

     git checkout -b start HEAD~5
     git checkout -b feature1
     git branch feature2
    

    Now use checkout and or cherry pick to make the branches. This is a more manual way of getting the exact trees that you want for each commit. Of interest is the patch option for add and reset. Also this syntax for git checkout is useful in this situation:

     git checkout <some sha1> -- some files
    

    Git gives you many ways of accomplishing what you want. Depending on how isolated your commits are, you may choose one method over another.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working on some code, which I use git to manage. Earlier,
I have a branch called experiment. git checkout master echo 'some changes' > a.txt
Some Background I have been using Git for a while now. The projects that
I have a remote git server that has been working great for months. Earlier
I have the next version of my code base that I've been working on
I'm using git. I have a branch, apifixes , that was branched from master
I've read this book section about git branches. I have create a branch called
I'm fairly new to Git, and have been working with it for only 3
I'm using git-svn to work with an SVN repository. My working copies have been
I have a local branch that is tracking of a remote branch on git.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.