UNPKG

epubjs

Version:

Render ePub documents in the browser, across many devices

57 lines (42 loc) 3.52 kB
<?xml version='1.0' encoding='utf-8'?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Pro Git - professional version control</title> <meta content="http://www.w3.org/1999/xhtml; charset=utf-8" http-equiv="Content-Type"/> <link href="stylesheet.css" type="text/css" rel="stylesheet"/> <style type="text/css"> @page { margin-bottom: 5.000000pt; margin-top: 5.000000pt; }</style> </head> <body class="calibre"> <h2 class="calibre4" id="calibre_pb_23">Branch Management</h2> <p class="calibre3">Now that you've created, merged, and deleted some branches, let's look at some branch-management tools that will come in handy when you begin using branches all the time.</p> <p class="calibre3">The <code class="calibre10">git branch</code> command does more than just create and delete branches. If you run it with no arguments, you get a simple listing of your current branches:</p> <pre class="calibre9"><code class="calibre10">$ git branch iss53 * master testing </code></pre> <p class="calibre3">Notice the <code class="calibre10">*</code> character that prefixes the <code class="calibre10">master</code> branch: it indicates the branch that you currently have checked out. This means that if you commit at this point, the <code class="calibre10">master</code> branch will be moved forward with your new work. To see the last commit on each branch, you can run <code class="calibre10">git branch -v</code>:</p> <pre class="calibre9"><code class="calibre10">$ git branch -v iss53 93b412c fix javascript issue * master 7a98805 Merge branch 'iss53' testing 782fd34 add scott to the author list in the readmes </code></pre> <p class="calibre3">Another useful option to figure out what state your branches are in is to filter this list to branches that you have or have not yet merged into the branch you're currently on. The useful <code class="calibre10">--merged</code> and <code class="calibre10">--no-merged</code> options have been available in Git since version 1.5.6 for this purpose. To see which branches are already merged into the branch you're on, you can run <code class="calibre10">git branch -merged</code>:</p> <pre class="calibre9"><code class="calibre10">$ git branch --merged iss53 * master </code></pre> <p class="calibre3">Because you already merged in <code class="calibre10">iss53</code> earlier, you see it in your list. Branches on this list without the <code class="calibre10">*</code> in front of them are generally fine to delete with <code class="calibre10">git branch -d</code>; you've already incorporated their work into another branch, so you're not going to lose anything.</p> <p class="calibre3">To see all the branches that contain work you haven't yet merged in, you can run <code class="calibre10">git branch --no-merged</code>:</p> <pre class="calibre9"><code class="calibre10">$ git branch --no-merged testing </code></pre> <p class="calibre3">This shows your other branch. Because it contains work that isn't merged in yet, trying to delete it with <code class="calibre10">git branch -d</code> will fail:</p> <pre class="calibre9"><code class="calibre10">$ git branch -d testing error: The branch 'testing' is not an ancestor of your current HEAD. If you are sure you want to delete it, run 'git branch -D testing'. </code></pre> <p class="calibre3">If you really do want to delete the branch and lose that work, you can force it with <code class="calibre10">-D</code>, as the helpful message points out.</p> </body> </html>