How to Merge Files Without Auto Commit in Git

John Wachira Feb 02, 2024
How to Merge Files Without Auto Commit in Git

This article will discuss merging a branch without generating a commit in Git. Before we get into the nitty-gritty, let’s look at some basic git merge concepts.

Merge Files Without Auto Commit in Git

We use the git merge command to merge branches in the context below.

If you are merging into the master branch, run:

$ git merge <branch-name>

If we run the git help merge command, we will see the help page for this command. The help page shows that the git merge commands call a commit by default.

We can pass the --commit argument to merge and commit the changes.

We pass the --no-commit flag to merge and stop Git from creating a commit. This way, we can make edits before committing the merge results.

The --ff flag will instruct Git to merge as a fast-forward merge, while the --no-ff creates a commit even if it is a fast-forward merge.

Hence, to merge without creating a commit message, run:

$ git merge <branch-name> --no-commit --no-ff

Git will perform the merge but pretend it has failed and will not generate a commit. This is your chance to inspect and tweak the merge results before committing.

Note that this will restrict you from making any changes to the files of your index. You cannot remove or add files while in this state.

Author: John Wachira
John Wachira avatar John Wachira avatar

John is a Git and PowerShell geek. He uses his expertise in the version control system to help businesses manage their source code. According to him, Shell scripting is the number one choice for automating the management of systems.

LinkedIn

Related Article - Git Merge