<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Git Branch &#8211; CodingQuerry</title>
	<atom:link href="http://localhost/category/git-branch/feed/?simply_static_page=44" rel="self" type="application/rss+xml" />
	<link>/</link>
	<description></description>
	<lastBuildDate>Thu, 20 Jun 2024 12:18:51 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.5.4</generator>
	<item>
		<title>How to Merge a Git Branch into Master</title>
		<link>/how-to-merge-a-git-branch-into-master/</link>
					<comments>/how-to-merge-a-git-branch-into-master/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Thu, 20 Jun 2024 12:18:51 +0000</pubDate>
				<category><![CDATA[Git Branch]]></category>
		<guid isPermaLink="false">/?p=14</guid>

					<description><![CDATA[Merging is an essential Git operation that combines changes from two branches. Its primary purpose is to integrate changes made in one branch (the source branch) into another (the target branch) and share those changes with other developers. This tutorial shows how to merge a Git branch into the master (main) branch. Prerequisites Git installed (follow our tutorials to install Git on]]></description>
										<content:encoded><![CDATA[<p>Merging is an essential Git operation that combines changes from two branches. Its primary purpose is to integrate changes made in one branch (the source branch) into another (the target branch) and share those changes with other developers.</p>
<p><strong>This tutorial shows how to merge a Git branch into the <code>master</code> (<code>main</code>) branch.</strong></p>
<div class="wp-block-image">
<div id="ftwp-postcontent">
<p class="h3">Prerequisites</p>
<ul>
<li>Git installed (follow our tutorials to install Git on Ubuntu, macOS, Windows, CentOS 7, or CentOS 8).</li>
<li>A Git repository.</li>
</ul>
<h2 id="ftoc-heading-1" class="wp-block-heading ftwp-heading">Merge a Git Branch into Master</h2>
<p>The <strong><code>master</code></strong> (or <strong><code>main</code></strong>) branch in Git is a repository&#8217;s default and primary branch. It usually represents the latest stable version of the project&#8217;s code. Merging another branch into <strong><code>master</code></strong> allows multiple developers to work on different features or fixes concurrently and then bring those changes together into a single branch.</p>
<div class="notice-note">
<div class="note-icon-wrapper"></div>
<div class="notice-text">
<p><strong>Note:</strong> Two terms describe the main branch &#8211; <strong><code>master</code></strong> and <strong><code>main</code></strong>. The more neutral term <strong><code>main</code></strong> has been more prevalent in recent years due to discussions about inclusivity. Previously, the only term for the main branch was <strong><code>master</code></strong>.</p>
</div>
</div>
<p>Follow the steps below to merge a branch into <strong><code>master</code></strong>:</p>
<h3 id="ftoc-heading-2" class="wp-block-heading ftwp-heading">Step 1: List All Git Branches</h3>
<p>List all the branches in your local Git repository using the <strong><code>git branch</code></strong> command:</p>
<pre class="wp-block-code copy-the-code-target"><code>git branch</code><button class="copy-the-code-button" title="Copy to Clipboard" data-style="svg-icon"></button></pre>
<div class="wp-block-image">
<figure class="aligncenter size-full"><img fetchpriority="high" decoding="async" class="wp-image-168388 entered lazyloaded" src="https://phoenixnap.com/kb/wp-content/uploads/2023/09/list-git-branches.png" sizes="(max-width: 700px) 100vw, 700px" srcset="https://phoenixnap.com/kb/wp-content/uploads/2023/09/list-git-branches.png 700w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/list-git-branches-300x78.png 300w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/list-git-branches-35x9.png 35w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/list-git-branches-36x9.png 36w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/list-git-branches-48x12.png 48w" alt="Listing all the local branches in Git." width="700" height="181" data-lazy-srcset="https://phoenixnap.com/kb/wp-content/uploads/2023/09/list-git-branches.png 700w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/list-git-branches-300x78.png 300w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/list-git-branches-35x9.png 35w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/list-git-branches-36x9.png 36w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/list-git-branches-48x12.png 48w" data-lazy-sizes="(max-width: 700px) 100vw, 700px" data-lazy-src="https://phoenixnap.com/kb/wp-content/uploads/2023/09/list-git-branches.png" data-ll-status="loaded" /></figure>
</div>
<p>The output shows we are currently on the <strong><code>master</code></strong> branch and lists all the other branches in the repository.</p>
<div class="notice-note">
<div class="note-icon-wrapper"></div>
<div class="notice-text">
<p><strong>Note:</strong> See how to list remote branches in Git.</p>
</div>
</div>
<h3 id="ftoc-heading-3" class="wp-block-heading ftwp-heading">Step 2: Switch to Master</h3>
<p>Ensure you are on the branch you want to merge into. In our case, the <strong><code>master</code></strong> branch. Use the <strong><code>git switch</code></strong> or <strong><code>git checkout</code></strong> command to switch to the master branch if you are not already on it:</p>
<pre class="wp-block-code copy-the-code-target"><code>git checkout master</code><button class="copy-the-code-button" title="Copy to Clipboard" data-style="svg-icon"></button></pre>
<div class="wp-block-image">
<figure class="aligncenter size-full"><img decoding="async" class="wp-image-168390 entered lazyloaded" src="https://phoenixnap.com/kb/wp-content/uploads/2023/09/switch-to-master-branch-git.png" sizes="(max-width: 700px) 100vw, 700px" srcset="https://phoenixnap.com/kb/wp-content/uploads/2023/09/switch-to-master-branch-git.png 700w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/switch-to-master-branch-git-300x34.png 300w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/switch-to-master-branch-git-35x4.png 35w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/switch-to-master-branch-git-36x4.png 36w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/switch-to-master-branch-git-48x5.png 48w" alt="Switching to the master branch in Git." width="700" height="80" data-lazy-srcset="https://phoenixnap.com/kb/wp-content/uploads/2023/09/switch-to-master-branch-git.png 700w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/switch-to-master-branch-git-300x34.png 300w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/switch-to-master-branch-git-35x4.png 35w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/switch-to-master-branch-git-36x4.png 36w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/switch-to-master-branch-git-48x5.png 48w" data-lazy-sizes="(max-width: 700px) 100vw, 700px" data-lazy-src="https://phoenixnap.com/kb/wp-content/uploads/2023/09/switch-to-master-branch-git.png" data-ll-status="loaded" /></figure>
</div>
<p>The command switches to the <strong><code>master</code></strong> branch.</p>
<h3 id="ftoc-heading-4" class="wp-block-heading ftwp-heading">Step 3: Merge Branch into Master</h3>
<p>After switching, use the <strong><code>git merge</code></strong> command to merge another branch into <strong><code>master</code></strong>. The merge creates a merge commit, bringing together multiple lines of development while preserving the history of the source branch.</p>
<p>Since merging is a type of commit, it also requires a commit message. There are two ways to specify the commit message:</p>
<ul>
<li>Using the <strong><code>merge</code></strong> command.</li>
<li>Specifying the commit message in a text editor.</li>
</ul>
<p><strong>1. Specify Commit Message Right Away</strong></p>
<p>To specify the <strong><code>merge</code></strong> message right away, use the following syntax:</p>
<pre class="wp-block-code copy-the-code-target"><code>git merge -m "Your merge commit message" [source_branch]</code><button class="copy-the-code-button" title="Copy to Clipboard" data-style="svg-icon"></button></pre>
<ul>
<li>The <strong><code>-m</code></strong> option is used to specify a commit message.</li>
<li>Replace <strong><code>"Your merge commit message"</code></strong> with the message you want to use for the merge commit. Enclose the message in double quotes.</li>
<li><strong><code>[source_branch]</code></strong> is the name of the branch you want to merge into your current branch.</li>
</ul>
<p>For example:</p>
<div class="wp-block-image">
<figure class="aligncenter size-full"><img decoding="async" class="wp-image-168398 entered lazyloaded" src="https://phoenixnap.com/kb/wp-content/uploads/2023/09/merge-branch-and-specify-commit-message.png" sizes="(max-width: 700px) 100vw, 700px" srcset="https://phoenixnap.com/kb/wp-content/uploads/2023/09/merge-branch-and-specify-commit-message.png 700w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/merge-branch-and-specify-commit-message-300x48.png 300w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/merge-branch-and-specify-commit-message-35x6.png 35w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/merge-branch-and-specify-commit-message-36x6.png 36w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/merge-branch-and-specify-commit-message-48x8.png 48w" alt="Merging a branch into master and specifying a commit message." width="700" height="112" data-lazy-srcset="https://phoenixnap.com/kb/wp-content/uploads/2023/09/merge-branch-and-specify-commit-message.png 700w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/merge-branch-and-specify-commit-message-300x48.png 300w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/merge-branch-and-specify-commit-message-35x6.png 35w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/merge-branch-and-specify-commit-message-36x6.png 36w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/merge-branch-and-specify-commit-message-48x8.png 48w" data-lazy-sizes="(max-width: 700px) 100vw, 700px" data-lazy-src="https://phoenixnap.com/kb/wp-content/uploads/2023/09/merge-branch-and-specify-commit-message.png" data-ll-status="loaded" /></figure>
</div>
<p>The command merges the <strong><code>examplebranch</code></strong> branch into the <strong><code>master</code></strong> branch and automatically sets the commit message to the one specified in the double quotes.</p>
<div class="notice-note">
<div class="note-icon-wrapper"></div>
<div class="notice-text">
<p><strong>Note:</strong> See how to resolve potential merge conflicts or change a commit message later.</p>
</div>
</div>
<p><strong>2. Specify Commit Message Separately</strong></p>
<p>Alternatively, use the following syntax to specify the commit message separately:</p>
<pre class="wp-block-code copy-the-code-target"><code>git merge [source_branch]</code><button class="copy-the-code-button" title="Copy to Clipboard" data-style="svg-icon"></button></pre>
<p>For example:</p>
<pre class="wp-block-code copy-the-code-target"><code>git merge examplebranch</code><button class="copy-the-code-button" title="Copy to Clipboard" data-style="svg-icon"></button></pre>
<p>The command starts the merge process and opens the default text editor, prompting you to enter a commit message for the merge:</p>
<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" class="wp-image-168401 entered lazyloaded" src="https://phoenixnap.com/kb/wp-content/uploads/2023/09/enter-merge-commit-message.png" sizes="(max-width: 700px) 100vw, 700px" srcset="https://phoenixnap.com/kb/wp-content/uploads/2023/09/enter-merge-commit-message.png 700w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/enter-merge-commit-message-300x90.png 300w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/enter-merge-commit-message-35x10.png 35w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/enter-merge-commit-message-36x11.png 36w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/enter-merge-commit-message-48x14.png 48w" alt="Specifying a commit message in a text editor." width="700" height="209" data-lazy-srcset="https://phoenixnap.com/kb/wp-content/uploads/2023/09/enter-merge-commit-message.png 700w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/enter-merge-commit-message-300x90.png 300w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/enter-merge-commit-message-35x10.png 35w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/enter-merge-commit-message-36x11.png 36w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/enter-merge-commit-message-48x14.png 48w" data-lazy-sizes="(max-width: 700px) 100vw, 700px" data-lazy-src="https://phoenixnap.com/kb/wp-content/uploads/2023/09/enter-merge-commit-message.png" data-ll-status="loaded" /></figure>
</div>
<p>In Windows, the Notepad++ editor opens, or whichever is the default one on your system. Specify the merge message, save and close the file, and the merge process completes:</p>
<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" class="wp-image-168400 entered lazyloaded" src="https://phoenixnap.com/kb/wp-content/uploads/2023/09/merge-branch-into-master.png" sizes="(max-width: 700px) 100vw, 700px" srcset="https://phoenixnap.com/kb/wp-content/uploads/2023/09/merge-branch-into-master.png 700w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/merge-branch-into-master-300x51.png 300w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/merge-branch-into-master-35x6.png 35w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/merge-branch-into-master-36x6.png 36w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/merge-branch-into-master-48x8.png 48w" alt="Merging a branch without specifying a commit message." width="700" height="119" data-lazy-srcset="https://phoenixnap.com/kb/wp-content/uploads/2023/09/merge-branch-into-master.png 700w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/merge-branch-into-master-300x51.png 300w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/merge-branch-into-master-35x6.png 35w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/merge-branch-into-master-36x6.png 36w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/merge-branch-into-master-48x8.png 48w" data-lazy-sizes="(max-width: 700px) 100vw, 700px" data-lazy-src="https://phoenixnap.com/kb/wp-content/uploads/2023/09/merge-branch-into-master.png" data-ll-status="loaded" /></figure>
</div>
<h3 id="ftoc-heading-5" class="wp-block-heading ftwp-heading">Step 4: Push Changes</h3>
<p>The final step is to push the local changes to the remote repository so everyone working on the project can fetch the latest version. The syntax is:</p>
<pre class="wp-block-code copy-the-code-target"><code>git push [remote_name]</code><button class="copy-the-code-button" title="Copy to Clipboard" data-style="svg-icon"></button></pre>
<p>Replace <strong><code>[remote_name]</code></strong> with the name of the remote repository. For example, if your remote repository is <strong><code>origin</code></strong>, run the following command:</p>
<pre class="wp-block-code copy-the-code-target"><code>git push origin</code><button class="copy-the-code-button" title="Copy to Clipboard" data-style="svg-icon"></button></pre>
<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" class="wp-image-168403 entered lazyloaded" src="https://phoenixnap.com/kb/wp-content/uploads/2023/09/push-changes-to-remote-repository.png" sizes="(max-width: 700px) 100vw, 700px" srcset="https://phoenixnap.com/kb/wp-content/uploads/2023/09/push-changes-to-remote-repository.png 700w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/push-changes-to-remote-repository-300x84.png 300w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/push-changes-to-remote-repository-35x10.png 35w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/push-changes-to-remote-repository-36x10.png 36w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/push-changes-to-remote-repository-48x13.png 48w" alt="Pushing local changes to a remote Git repository." width="700" height="196" data-lazy-srcset="https://phoenixnap.com/kb/wp-content/uploads/2023/09/push-changes-to-remote-repository.png 700w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/push-changes-to-remote-repository-300x84.png 300w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/push-changes-to-remote-repository-35x10.png 35w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/push-changes-to-remote-repository-36x10.png 36w, https://phoenixnap.com/kb/wp-content/uploads/2023/09/push-changes-to-remote-repository-48x13.png 48w" data-lazy-sizes="(max-width: 700px) 100vw, 700px" data-lazy-src="https://phoenixnap.com/kb/wp-content/uploads/2023/09/push-changes-to-remote-repository.png" data-ll-status="loaded" /></figure>
</div>
<p>The command pushes the changes to the remote repository, where they become available to everyone working on the project.</p>
<p class="h3">Conclusion</p>
<p>This tutorial showed how to merge a Git branch into the <strong><code>master</code></strong> branch. Merging is an essential Git procedure that allows users to bring together multiple lines of development.</p>
<p>Next, see how to merge a master branch into another one or learn the difference between git rebase and git merge.</p>
</div>
<div id="was-this-helpful" data-post-id="168385" data-thank-text="Thank you for your feedback!"></div>
</div>
]]></content:encoded>
					
					<wfw:commentRss>/how-to-merge-a-git-branch-into-master/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
