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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:23:20+00:00 2026-06-15T12:23:20+00:00

I have a local git repo, one remote repo. I made 5 commits to

  • 0

I have a local git repo, one remote repo.
I made 5 commits to local repo since last pull from remote.

Now I need to push to remote. And I need to squash my last 5 commits.

I can do it by git rebase -i HEAD~5

But it’s not good. I don’t want to change anything in my local repo. I want to push one squashed commit to remote and leave 5 unchanged commits in my local repo.

Any ideas?

UPD:
what about if I have my local repo with 5 commits. and I need to create new remote repo to share my code with others. How to squash commits for this new repo?

  • 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-15T12:23:21+00:00Added an answer on June 15, 2026 at 12:23 pm

    Slight variation from Titas‘s answer, without touching your master branch, and squashing on a new branch (that you would push to your new repo)

     git remote add newrepo url://of/your/new/repo
     git checkout -b newbranch master
     git merge --squash master 
     git push -u newrepo newbranch:master
    

    But that would push the full history of master, +1 (squashed) commit, on your new repo.

    If you wanted a branch new history, with your repo as after the 5 new commits, it is easier to:

    • clone locally your repo,
    • remove the .git in that local clone,
    • git init. (ie, re-create a new local git repo from all the existing files),
    • add everything and do one commit,
    • add your remote (to your new remote repo),
    • and push that one commit of your new local repo.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a local git repo, and I have a remote git repo. What
I accidentally deleted a few files from my local git repo. I have not
I want to push my local files, and have them on a remote repo,
I currently have a following Git workflow local normal git repo -> remote bare
So if I have a Git repo on my local machine and I send
I have two git repositories: report.git (Master on remote location) cloned.git (Local) I lost
I'm committing changes to my local git repo, then I push the changes to
In my local repo I have one commit with an incorrect commit message. I've
I have a local git repo created by Qt Creator during the New Project
I have a Git repository on my local machine that I cloned from my

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.