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

The Archive Base Latest Questions

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

I have a branch, mybranch, that has six commits and stems from commit C.

  • 0

I have a branch, mybranch, that has six commits and stems from commit C. I would like to create a new branch, also based on commit C, that effectively includes all the commits from mybranch, squashed into one commit. What’s the easiest way to do this?

I need to do this due to the mantra of “squash before you git-push”. For the new branch, I don’t want any mention of mybranch in the history pushed up to the remote server. The reason I want to create a whole new branch used to push is because I’d like to keep all the commits in mybranch for reference.

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

    Why only push squashed commits? That sounds crazy (and wrong).

    But to answer your question:

    git checkout -b newbranch # checkout new branch
    git reset --soft C # move to commit C
    git commit -m 'squashed commit'
    

    Another possibility would be to use rebase -i to squash/fixup all commits into a single one:

    git checkout -b newbranch
    git rebase -i C # now, replace every 'pick' with 'fixup'/'squash' except the first one
    

    Also of interest is git merge --squash:

    Produce the working tree and index state as if a real merge happened (except for the merge information), but do not actually make a commit or move the HEAD, nor record $GIT_DIR/MERGE_HEAD to cause the next git commit command to create a merge commit. This allows you to create a single commit on top of the current branch whose effect is the same as merging another branch (or more in case of an octopus).

    git checkout -b newbranch C # create newbranch at commit C
    git merge --squash mybranch
    git commit -m 'squashed commit'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using git. I have a branch, apifixes , that was branched from master
I have a branch which I created from the trunk some time ago. Since
I have a branch in a badly structured svn repo that needs to be
In svn, I have a branch which was created, say at revision 22334. Commits
I am new to Git and I seem to have one branch too many
I am new to git and I would like to know how to tackle
I have a branch that should be available to other contributors and that should
I have a branch checkout that is clean (no modifications), but I cannot reintegrate
I have a case where my branch represents a new version which in it
I have a local branch that tracks an upstream SVN branch, in which heavy

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.