> For the complete documentation index, see [llms.txt](https://www.pranaypourkar.co.in/the-programmers-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.pranaypourkar.co.in/the-programmers-guide/git/workflows/merge-strategies/fast-forward-vs-no-fast-forward.md).

# Fast-forward vs No-fast-forward

## About

When merging branches in Git, the term **fast-forward** or **no-fast-forward** (`--no-ff`) describes **how Git integrates the changes** from one branch into another.

They **do not affect the code content**, but **how Git writes commit history** during the merge.

## What Is a Fast-Forward Merge ?

A **fast-forward merge** happens **when the branch being merged in is directly ahead of the current branch**, with **no divergent history**. Git doesn’t need to create a new commit — it simply **moves the pointer** forward.

#### Visual Before Merge

```
main:  A -- B -- C
                   \
                 (feature): D -- E
```

If `main` is at `C` and you merge `feature`, and no new commits exist on `main`, Git will just move `main` forward.

#### After Fast-Forward Merge

```
main:  A -- B -- C -- D -- E
```

No merge commit is created.

#### Command

```bash
git checkout main
git merge feature
```

If `main` hasn't diverged, Git does a fast-forward by default.

## What Is a No-Fast-Forward Merge ?

A **no-fast-forward merge** forces Git to **always create a merge commit**, even if a fast-forward is possible.

This makes the **merge operation explicit in the history**, preserving the fact that a merge occurred and from which branch.

#### Visual Before

```
main:       A -- B -- C
                       \
                      (feature): D -- E
```

**After no-ff merge**

```
main:        A -- B -- C ------ M
                        \       /
                         D -- E
```

Now there is a **merge commit `M`**, showing the integration point.

#### Command:

```bash
git checkout main
git merge --no-ff feature
```

## Settings to Enforce Behavior

#### Always do no-fast-forward merges:

```bash
git config --global merge.ff false
```

This is useful in organizations that want **explicit merge tracking**.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://www.pranaypourkar.co.in/the-programmers-guide/git/workflows/merge-strategies/fast-forward-vs-no-fast-forward.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
