<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/how-to-flatten-git-commits-a-s1dfu59" -->

---
title: How to Flatten git Commits | daily.dev
description: How to flatten commits before rebasing off of the main branch. With just one single commit, you avoid the stop-start nature of fixing merge conflicts with...
canonical: https://daily.dev/posts/how-to-flatten-git-commits-a-s1dfu59
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: How to Flatten git Commits | daily.dev
og:description: How to flatten commits before rebasing off of the main branch. With just one single commit, you avoid the stop-start nature of fixing merge conflicts with...
og:url: https://daily.dev/posts/how-to-flatten-git-commits-a-s1dfu59
og:image: https://api.daily.dev/og/posts/a_S1DFu59.png
og:image:alt: How to Flatten git Commits
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Flatten git Commits

**[David Walsh](https://daily.dev/sources/dwb)** · 1 min read · 11 upvotes · 0 comments

## Summary

How to flatten commits before rebasing off of the main branch. With just one single commit, you avoid the stop-start nature of fixing merge conflicts with multiple commits. To flatten the commits before the rebase, you can slightly modify the original command: git rebase -i HEAD~[NUMBER_OF_COMMITS]

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://davidwalsh.name/flatten-git-commits>

---

Tags: [#git](https://daily.dev/tags/git)

[View this post on daily.dev](https://daily.dev/posts/how-to-flatten-git-commits-a-s1dfu59)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"How to Flatten git Commits","url":"https://daily.dev/posts/how-to-flatten-git-commits-a-s1dfu59","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/how-to-flatten-git-commits-a-s1dfu59"},"datePublished":"2022-01-07T02:12:17.950Z","dateModified":"2022-01-07T02:12:17.961Z","description":"How to flatten commits before rebasing off of the main branch. With just one single commit, you avoid the stop-start nature of fixing merge conflicts with...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/5f0a5a72eb47f918ffebc47fedef8081","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/5f0a5a72eb47f918ffebc47fedef8081","isAccessibleForFree":true,"articleSection":"David Walsh","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"David Walsh","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/5ecdb402b07a45598472bdd38a38de15","url":"https://daily.dev/sources/dwb"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/how-to-flatten-git-commits-a-s1dfu59","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":11},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"git","timeRequired":"PT1M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"David Walsh","item":"https://daily.dev/sources/dwb"},{"@type":"ListItem","position":3,"name":"How to Flatten git Commits"}]}
```

