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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:45:45+00:00 2026-06-09T00:45:45+00:00

I have two branches A and B. What I want to do is to

  • 0

I have two branches A and B. What I want to do is to create a new (merge) commit on A with the current state of A as parent that refers to the file tree described by B discarding anything from A.
Basically the history of B should be squashed into a single commit.

The concrete repository state consists of two independend branches, that do not have a common ancestor (coming from two formererly independent repositories), but that describe the same content.
Now I want to find a “git”-way to bring them together. A basic solution (without git) would be to
checkout A and just copy the content of B into the working tree and do a git commit. That is basically what I’ve done earlier to propagate the content of the second repository into the first one.

To do it with git I’ve tried

git checkout A
git merge --squash B

But unforunately it generated merge conflicts for all files that differ between A and B, what is definately not what I expected.

Basically something like

git merge --squash -s theirs

should do the job, but the merge strategy theirs does not exist. Reading the docu shows
the possibility of using something like

git merge -X theirs

which is an option to the merge strategy recursive. But this still does a merge of non-conflicting chunks. Only the conflicting chunks are taken directly from theirs.

  • 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-06-09T00:45:46+00:00Added an answer on June 9, 2026 at 12:45 am

    As you comment, from all the merge –theirs strategies I list in “git command for making one branch like another“, the second option is close to what you need:

    Shows as a merge, with ours as the first parent.
    (proposed by jcwenger)

    git checkout -b tmp upstream
    git merge -s ours thebranch         # ignoring all changes from downstream
    git checkout downstream
    git merge --squash tmp               # apply changes from tmp but not as merge.
    git rev-parse upstream > .git/MERGE_HEAD #record upstream 2nd merge head
    git commit -m "rebaselined the branch from upstream" # make the commit.
    git branch -D tmp                    # deleting tmp
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to merge two branches that have been separated for a while and
I have two branches. I want to create a new one. How do I
Given that two branches have diverged and a specific commit from one branch (and
I have two branches:master and v2. I want to merge v2 in master so
I have two branches: master and dev I want to create a "feature branch"
Is Mercurial always using the external merge tools when two branches that are merging
I have a trunk (A) and two branches (B and C). When I merge
I'm using ANTLR 3 to create an AST. I want to have two AST
I have two branches that are different enough that rebasing seems to not work
Related but not quite what I am looking for merge-two-branches-what-direction. Situation: I have inherited

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.