How to Merge the Development Branch Into Master in Git

John Wachira Mar 11, 2025 Git Git Merge
  1. Understanding the Basics of Git Branching
  2. Method 1: Merging Using the Command Line
  3. Method 2: Merging Using a GUI Tool
  4. Method 3: Using Pull Requests (PRs) on Platforms like GitHub
  5. Conclusion
  6. FAQ
How to Merge the Development Branch Into Master in Git

Merging a development branch into the master branch in Git is a crucial part of the software development workflow. It allows you to incorporate new features, bug fixes, or changes into the main codebase. This process can seem daunting, especially for beginners, but it’s straightforward once you understand the steps involved.

In this article, we will walk you through the essential commands and methods to effectively merge your development branch into the master branch. Whether you’re collaborating with a team or working solo, mastering this skill will enhance your version control capabilities and streamline your development process.

Understanding the Basics of Git Branching

Before diving into the merging process, it’s essential to grasp the concept of branching in Git. A branch in Git is essentially a lightweight movable pointer to a commit. The master branch is typically where the stable version of your project resides, while development branches are used for ongoing work. When you merge a development branch into master, you are integrating all the changes made in that branch back into the main line of development.

It’s also important to note that Git uses a three-way merge algorithm, which means it takes into account the base of the branch you are merging, the tip of the master branch, and the tip of the development branch. This ensures that the merge is done efficiently and any conflicts are resolved.

Method 1: Merging Using the Command Line

The most common way to merge a development branch into master is through the command line. Here’s how to do it step by step:

  1. First, ensure you are in your project directory.
  2. Checkout to the master branch using the command:
git checkout master
  1. Next, pull the latest changes from the remote repository:
git pull origin master
  1. Now, you can merge your development branch into master. Replace development-branch with the name of your actual branch:
git merge development-branch
  1. If there are no conflicts, Git will automatically merge the branches. If there are conflicts, you will need to resolve them manually.
  2. Finally, push the merged changes back to the remote master branch:
git push origin master

Output:

Merge made by the 'recursive' strategy.

Merging via the command line is straightforward and gives you complete control over the process. Remember, if conflicts arise, Git will indicate which files need attention. You’ll need to edit those files, mark the conflicts as resolved, and then complete the merge. This method is particularly useful for developers who prefer working directly with Git commands.

Method 2: Merging Using a GUI Tool

If you prefer a graphical interface over command-line commands, many Git GUI tools can help you merge branches easily. Tools like GitHub Desktop, SourceTree, or GitKraken provide a user-friendly way to manage branches and merges. Here’s a general guide on how to merge branches using a GUI tool:

  1. Open your Git GUI application and navigate to your repository.
  2. Switch to the master branch. This is usually done by selecting the branch from a dropdown menu.
  3. Look for an option to fetch or pull the latest changes from the remote repository.
  4. Once you have the latest master branch, locate your development branch in the interface.
  5. There should be an option to merge branches. Select your development branch and initiate the merge.
  6. If there are conflicts, the GUI tool will typically highlight them, allowing you to resolve them visually.
  7. After resolving any conflicts, finalize the merge and push your changes back to the remote repository.

Output:

Merge completed successfully.

Using a GUI tool can simplify the merging process, especially for those who may not be as comfortable with command-line interfaces. These tools often provide visual aids that make it easier to understand the changes being merged, making them a great choice for beginners or those who prefer a more visual approach.

Method 3: Using Pull Requests (PRs) on Platforms like GitHub

Another popular method for merging a development branch into master is through Pull Requests (PRs) on collaborative platforms like GitHub. This method not only merges your changes but also allows for code review and discussion among team members. Here’s how to do it:

  1. Push your development branch to the remote repository:
git push origin development-branch
  1. Navigate to your repository on GitHub and you’ll usually see an option to create a Pull Request for your recently pushed branch.
  2. Click on “Compare & pull request.”
  3. Add a title and description for your PR, explaining the changes you made.
  4. Assign reviewers if needed and click on “Create pull request.”
  5. Once the PR is reviewed and approved, you can merge it into the master branch directly from the GitHub interface.
  6. After merging, you can delete the development branch if it’s no longer needed.

Output:

Pull request merged successfully.

Using Pull Requests is a great practice, especially in team environments. It encourages collaboration and ensures that multiple eyes review the code before it becomes part of the main codebase. This method not only merges the branches but also helps maintain code quality and integrity.

Conclusion

Merging a development branch into the master branch in Git is a fundamental skill for any developer. Whether you opt for command-line commands, a GUI tool, or Pull Requests on platforms like GitHub, understanding the merging process will enhance your workflow and collaboration efforts. Remember to always resolve conflicts carefully and ensure that your master branch remains stable. By mastering these techniques, you’ll be well on your way to becoming a proficient Git user.

FAQ

  1. What is the difference between merging and rebasing in Git?
    Merging combines changes from different branches, while rebasing rewrites commit history to create a linear progression of changes.

  2. Can I merge without pulling the latest changes first?
    It’s not recommended, as you may miss updates made by others, leading to conflicts during the merge.

  3. What happens if there are merge conflicts?
    You will need to manually resolve conflicts in the affected files before completing the merge.

  4. Is it safe to delete the development branch after merging?
    Yes, if the branch is no longer needed, you can safely delete it to keep your repository clean.

  5. How can I undo a merge if I make a mistake?
    You can use git merge --abort to revert to the state before the merge if you haven’t committed yet. If you have, you can use git reset --hard HEAD~1 to undo the last commit.

Enjoying our tutorials? Subscribe to DelftStack on YouTube to support us in creating more high-quality video guides. Subscribe
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