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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:23:19+00:00 2026-05-19T02:23:19+00:00

I have two branches, email and staging . staging is the latest one and

  • 0

I have two branches, email and staging. staging is the latest one and I no longer need the old changes in email branch, yet I don’t want to delete them.

So I just want to dump all the contents of staging into email so that they both point to the same commit. Is that possible?

  • 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-19T02:23:20+00:00Added an answer on May 19, 2026 at 2:23 am

    You can use the ‘ours’ merge strategy:

    $ git checkout staging
    $ git merge -s ours email # Merge branches, but use our (=staging) branch head
    $ git checkout email
    $ git merge staging
    

    The question requires the commits of the email branch to be kept. They must not be made unreachable, which rules out any reset-based approaches or deleting and recreating the branch.

    I no longer need the old changes in email branch, yet I don’t want to delete them.

    To keep commits of both branches reachable, one or more references must exist that point to those commits. You can always keep two references (staging and email), but the question asks to get rid of one of the refs. Therefore, the branches need to be merged somehow.


    EDIT 2020-07-30:

    I thought a bit more about this question and possible solutions. If you absolutely require the merge parents in the correct order, need to perform this action with a single command line invocation, and don’t mind running plumbing commands, you can do the following:

    $ git checkout A
    $ git merge --ff-only $(git commit-tree -m "Throw away branch 'A'" -p A -p B B^{tree})
    

    This basically acts like the (non-existent) merge -s theirs strategy.
    You can find the resulting history in the plumbing branch of the demo repository

    Not very readable and not as easy to remember compared to the -s ours switch, but it does the job. The resulting tree is again the same as branch B:

    $ git rev-parse A^{tree} B^{tree} HEAD^{tree}
    3859ea064e85b2291d189e798bfa1bff87f51f3e
    0389f8f2a3e560b639d82597a7bc5489a4c96d44
    0389f8f2a3e560b639d82597a7bc5489a4c96d44
    

    EDIT 2020-07-29:

    There seems to be a lot of confusion as to what the difference between -s ours and -X ours (the latter being equivalent to -s recursive --strategy-option ours) is. Here’s a small example to show the two results from using these two methods. I also recommend reading the question and answers of (Git Merging) When to use 'ours' strategy, 'ours' option and 'theirs' option?

    First, setup a repository with 2 branches and 3 commits (1 base commit, and 1 commit per branch). You can find the sample repository on GitHub

    $ git init
    $ echo 'original' | tee file1 file2 file3
    $ git commit -m 'initial commit'
    $ git branch A
    $ git branch B
    $ git checkout A
    $ echo 'A' > file1
    $ git commit -m 'change on branch A' file1
    $ git checkout B
    $ echo 'B' > file2
    $ git commit -m 'change on branch B' file2
    

    Now, let’s try the strategy option (doesn’t really matter if we use theirs or ours for this explanation):

    $ git merge -X ours A
    $ cat file*
    A
    B
    original
    

    We end up with a merge of both branches’ contents (branch "strategy-option" in the sample repo). Compare that to using the merge strategy (re-init your repository or reset branch, before executing the next steps):

    $ git merge -s ours A
    $ cat file*
    original
    B
    original
    

    The result is quite different (branch "merge-strategy" in the sample repo). With the strategy option, we get a merge result of both branches, with the strategy we throw away any changes which happened in the other branch.

    You will also notice that the commit created by the merge-strategy in fact points to the exact same tree as the latest commit of "our" branch, while the strategy-option created a new, previously-unseen tree:

    $ git rev-parse A^{tree} B^{tree} merge-strategy^{tree} strategy-option^{tree}
    3859ea064e85b2291d189e798bfa1bff87f51f3e
    0389f8f2a3e560b639d82597a7bc5489a4c96d44
    0389f8f2a3e560b639d82597a7bc5489a4c96d44
    5b09d34a37a183723b409d25268c8cb4d073206e
    

    OP indeed asked for "I no longer need the old changes in […] branch" and "So I just want to dump all the contents of [A] into [B]", which is not possible to do with a strategy option. Using the ‘ours’ merge strategy is one possibility of many, but likely the easiest (other possibilities include using low level commands of Git such as write-tree and commit-tree).

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

Sidebar

Related Questions

I have two branches with several commits each. On one branch, I can go
I have two branches: local branch (the one which I work with) remote branch
We have two branches. One is a Release Branch (RB) taken from the trunk.
I have two branches: master and dev I want to create a "feature branch"
I have two service pack branches coming out of one ‘main’ branch in TFS
Currently I have two branches in a Mercurial repository. One the default branch where
We have two branches: 1. HEAD - the latest version (AKA Trunc) 2. PROD
I have two branches : X and Y. I want to replace a Y's
I have two branches in mercurial.. default named |r1 |r2 |r3 -------- named branch
I have two branches:master and v2. I want to merge v2 in master so

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.