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 6020083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:30:59+00:00 2026-05-23T03:30:59+00:00

Here’s the scenario: I’ve created a new repository for a codebase and made a

  • 0

Here’s the scenario: I’ve created a new repository for a codebase and made a few commits, but I’ve decided there’s some part of that codebase that should be in its own branch rather than on master. How do I separate that code off into another branch so that master is “unaware” of it? Obviously I can’t just create the branch and then delete the code from master, since any subsequent merges from master into the new branch will delete the code in the branch too.

I’m sure this has a trivial answer, but I can’t think how it should be done 🙂

  • 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-23T03:31:00+00:00Added an answer on May 23, 2026 at 3:31 am

    If you can rebase master (i.e. nobody else has the changes you want to move to the branch), I would use git rebase -i to rearrange the commits in master, so that all commits that should be in the branch are after all commits that should stay in master. After that, create the branch and reset master, so that it doesn’t contain any of the branch commits.

    For example, if you had commits (where B denotes a commit you want to move, and M one that should stay):

    M1---B1---M2---B2---M3
    

    rebase them into

    M1---M2---M3---B1---B2
    

    Create the new branch and git reset --hard master to M3.

    If you can’t rebase master, create your branch, git revert the changes you don’t want on master, and then do git merge -s ours master. This effectively tells the branch that you know about the revert and you don’t want it there.

    After that, if you merge master into the branch, changes in master are correctly merged, but the revert isn’t. What’s more, if you then decide the branch is done and you want to merge back into master, it works correctly too – all changes from the branch are merged, including those that were reverted.

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

Sidebar

Related Questions

Here's the scenario: I have a local git repository that mirrors the contents of
Here is some code I made :) @echo off set source=R:\Contracts\ set destination=R:\Contracts\Sites\ ROBOCOPY
here is the scenario 1: user starts to type some word, autocomplete engine shows
Here's my scenario - I have an SSIS job that depends on another prior
Here is the scenario: I'm writing an app that will watch for any changes
Here's some of my production code (I had to force line breaks): task =
Here's what I'm trying to do... It's quite simple and obviously there must be
here is my scenario: workstation A : Sun JDK 1.6 workstation B : Sun
Here is an example: I have a file 1.js, which has some functions. I
Here's a basic regex technique that I've never managed to remember. Let's say I'm

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.