{"id":118,"date":"2022-10-02T17:17:43","date_gmt":"2022-10-02T21:17:43","guid":{"rendered":"https:\/\/hongpanz.com\/?p=118"},"modified":"2022-11-02T20:48:00","modified_gmt":"2022-11-03T00:48:00","slug":"basis-of-git","status":"publish","type":"post","link":"https:\/\/hongpanz.com\/index.php\/2022\/10\/02\/basis-of-git\/","title":{"rendered":"Basis of Git"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_35_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" style=\"display: none;\"><label for=\"item\" aria-label=\"Table of Content\"><span style=\"display: flex;align-items: center;width: 35px;height: 30px;justify-content: center;\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/label><input type=\"checkbox\" id=\"item\"><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/hongpanz.com\/index.php\/2022\/10\/02\/basis-of-git\/#Status_of_files\" title=\"Status of files\">Status of files<\/a><ul class='ez-toc-list-level-3'><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/hongpanz.com\/index.php\/2022\/10\/02\/basis-of-git\/#Commands\" title=\"Commands\">Commands<\/a><ul class='ez-toc-list-level-4'><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/hongpanz.com\/index.php\/2022\/10\/02\/basis-of-git\/#git_status\" title=\"git status\">git status<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/hongpanz.com\/index.php\/2022\/10\/02\/basis-of-git\/#git_add\" title=\"git add\">git add<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/hongpanz.com\/index.php\/2022\/10\/02\/basis-of-git\/#git_diff\" title=\"git diff\">git diff<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/hongpanz.com\/index.php\/2022\/10\/02\/basis-of-git\/#git_commit\" title=\"git commit\">git commit<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/hongpanz.com\/index.php\/2022\/10\/02\/basis-of-git\/#git_rm\" title=\"git rm\">git rm<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/hongpanz.com\/index.php\/2022\/10\/02\/basis-of-git\/#git_mv\" title=\"git mv\">git mv<\/a><\/li><\/ul><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/hongpanz.com\/index.php\/2022\/10\/02\/basis-of-git\/#Undoing_Things\" title=\"Undoing Things\">Undoing Things<\/a><ul class='ez-toc-list-level-3'><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/hongpanz.com\/index.php\/2022\/10\/02\/basis-of-git\/#Commands-2\" title=\"Commands\">Commands<\/a><ul class='ez-toc-list-level-4'><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/hongpanz.com\/index.php\/2022\/10\/02\/basis-of-git\/#additional_commit\" title=\"additional commit\">additional commit<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/hongpanz.com\/index.php\/2022\/10\/02\/basis-of-git\/#unstage_files\" title=\"unstage files\">unstage files<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/hongpanz.com\/index.php\/2022\/10\/02\/basis-of-git\/#unmodifying_a_modified_file\" title=\"unmodifying a modified file\">unmodifying a modified file<\/a><\/li><\/ul><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/hongpanz.com\/index.php\/2022\/10\/02\/basis-of-git\/#Working_with_Remotes\" title=\"Working with Remotes\">Working with Remotes<\/a><ul class='ez-toc-list-level-3'><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/hongpanz.com\/index.php\/2022\/10\/02\/basis-of-git\/#Commands-3\" title=\"Commands\">Commands<\/a><ul class='ez-toc-list-level-4'><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/hongpanz.com\/index.php\/2022\/10\/02\/basis-of-git\/#show_your_remotes\" title=\"show your remotes\">show your remotes<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/hongpanz.com\/index.php\/2022\/10\/02\/basis-of-git\/#add_remote_repositories\" title=\"add remote repositories\">add remote repositories<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/hongpanz.com\/index.php\/2022\/10\/02\/basis-of-git\/#fetch_and_pull\" title=\"fetch and pull\">fetch and pull<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/hongpanz.com\/index.php\/2022\/10\/02\/basis-of-git\/#push_to_your_remotes\" title=\"push to your remotes\">push to your remotes<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-20\" href=\"https:\/\/hongpanz.com\/index.php\/2022\/10\/02\/basis-of-git\/#compare_two_repositories\" title=\"compare two repositories\">compare two repositories<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-21\" href=\"https:\/\/hongpanz.com\/index.php\/2022\/10\/02\/basis-of-git\/#inspect_a_remote\" title=\"inspect a remote\">inspect a remote<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-22\" href=\"https:\/\/hongpanz.com\/index.php\/2022\/10\/02\/basis-of-git\/#rename_and_remove\" title=\"rename and remove\">rename and remove<\/a><\/li><\/ul><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-23\" href=\"https:\/\/hongpanz.com\/index.php\/2022\/10\/02\/basis-of-git\/#Branching\" title=\"Branching\">Branching<\/a><ul class='ez-toc-list-level-3'><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-24\" href=\"https:\/\/hongpanz.com\/index.php\/2022\/10\/02\/basis-of-git\/#Commands-4\" title=\"Commands\">Commands<\/a><ul class='ez-toc-list-level-4'><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-25\" href=\"https:\/\/hongpanz.com\/index.php\/2022\/10\/02\/basis-of-git\/#check_branches\" title=\"check branches\">check branches<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-26\" href=\"https:\/\/hongpanz.com\/index.php\/2022\/10\/02\/basis-of-git\/#create_a_branch\" title=\"create a branch\">create a branch<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-27\" href=\"https:\/\/hongpanz.com\/index.php\/2022\/10\/02\/basis-of-git\/#check_the_pointer\" title=\"check the pointer\">check the pointer<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-28\" href=\"https:\/\/hongpanz.com\/index.php\/2022\/10\/02\/basis-of-git\/#switch_branches\" title=\"switch branches\">switch branches<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-29\" href=\"https:\/\/hongpanz.com\/index.php\/2022\/10\/02\/basis-of-git\/#remove_branches\" title=\"remove branches\">remove branches<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-30\" href=\"https:\/\/hongpanz.com\/index.php\/2022\/10\/02\/basis-of-git\/#merge_branches\" title=\"merge branches\">merge branches<\/a><\/li><\/ul><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n\n<h2><span class=\"ez-toc-section\" id=\"Status_of_files\"><\/span>Status of files<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><img src=\"http:\/\/hongpanz.com\/wp-content\/uploads\/2022\/10\/image-20220927111011597.png\" alt=\"\" \/><\/p>\n<ul>\n<li>Modified means that you have changed the file but have not committed it to your database yet.<\/li>\n<li>Staged means that you have marked a modified file in its current version to go into your next commit snapshot.<\/li>\n<li>Committed means that the data is safely stored in your local database.<\/li>\n<li>Untracked basically means that Git sees a file you didn\u2019t have in the  previous snapshot (commit), and which hasn\u2019t yet been staged; Git won\u2019t  start including it in your commit snapshots until you explicitly tell it to do so. It does this so you don\u2019t accidentally begin including generated binary  files or other files that you did not mean to include.<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"Commands\"><\/span>Commands<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h4><span class=\"ez-toc-section\" id=\"git_status\"><\/span>git status<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<pre><code class=\"language-bash line-numbers\">#check the status of all files\ngit status\n\n#short status\ngit status -s\n<\/code><\/pre>\n<pre><code class=\"language-bash line-numbers\">#output of short status\n$ git status -s\n M README\nMM Rakefile\nA  lib\/git.rb\nM  lib\/simplegit.rb\n?? LICENSE.txt\n<\/code><\/pre>\n<p>New files that aren\u2019t tracked have a <code>??<\/code> next to them, new files that have been added to the staging area have an <code>A<\/code>, modified files have an <code>M<\/code> and so on. There are two columns to the output\u2009\u2014\u2009the left-hand column indicates the status of the staging area and the right-hand column indicates the  status of the working tree. So for example in that output, the <code>README<\/code> file is modified in the working directory but not yet staged, while the <code>lib\/simplegit.rb<\/code> file is modified and staged. The <code>Rakefile<\/code> was modified, staged and then modified again, so there are changes to it that are both staged and unstaged.<\/p>\n<h4><span class=\"ez-toc-section\" id=\"git_add\"><\/span>git add<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p><code>git add<\/code> is a multipurpose command\u2009\u2014\u2009you use it to <strong>begin  tracking new files<\/strong>, to <strong>stage files<\/strong>, and to do other things like <strong>marking  merge-conflicted files as resolved<\/strong>. It may be helpful to think of it more as \u201cadd precisely this content to  the next commit\u201d rather than \u201cadd this file to the project\u201d.<\/p>\n<pre><code class=\"language-bash line-numbers\">git add &lt;filename&gt;\n\n#add all changes in one batch\ngit add --all\n<\/code><\/pre>\n<h4><span class=\"ez-toc-section\" id=\"git_diff\"><\/span>git diff<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<pre><code class=\"language-bash line-numbers\">#To see what you\u2019ve changed but not yet staged\ngit diff\n\n#to see what you\u2019ve staged that will go into your next commit\ngit diff --staged\n#OR\ngit diff --cached\n<\/code><\/pre>\n<h4><span class=\"ez-toc-section\" id=\"git_commit\"><\/span>git commit<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>This command commit all the staged changes in batches. Anything that is still unstaged\u2009\u2014\u2009any files you have created or modified that you haven\u2019t run <code>git add<\/code> on since you edited them\u2009\u2014\u2009won\u2019t go into this commit.<\/p>\n<pre><code class=\"language-bash line-numbers\">git commit -m 'message'\n\n#to skip staging\n#this command automatically stage all tracked files\ngit commit -a -m 'message'\n<\/code><\/pre>\n<h4><span class=\"ez-toc-section\" id=\"git_rm\"><\/span>git rm<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>To remove a file from Git, you have to remove it from your tracked files (more accurately, remove it from your staging area) and then commit. The <code>git rm<\/code> command does that, and also removes the file  from your working directory so you don\u2019t see it as an untracked file the next time around.<\/p>\n<p>If you simply remove the file from your working directory, it shows up under the \u201cChanges not staged for commit\u201d (that is, <em>unstaged<\/em>) area of your <code>git status<\/code> output.<\/p>\n<p>If you modified the file or had already added it to the staging area, you must force the removal with the <code>-f<\/code> option. This is a safety feature to prevent accidental removal of data that  hasn\u2019t yet been recorded in a snapshot and that can\u2019t be recovered from  Git.<\/p>\n<pre><code class=\"language-bash line-numbers\">git rm &lt;filename&gt;\n\ngit rm log\/\\*.log\ngit rm \\*~\n\ngit rm -f &lt;filename&gt;\n\n#untrack a file instead of removing it\ngit rm --cached README\n<\/code><\/pre>\n<h4><span class=\"ez-toc-section\" id=\"git_mv\"><\/span>git mv<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>rename or move a file<\/p>\n<pre><code class=\"language-bash line-numbers\">git mv &lt;filename&gt; &lt;new_filename&gt;\n<\/code><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Undoing_Things\"><\/span>Undoing Things<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Be careful, because you can\u2019t always undo some of these undos. This is one of the few areas in Git where you may lose some work if you do it wrong.<\/p>\n<p>Remember, anything that is <em>committed<\/em> in Git can almost always be recovered. Even commits that were on branches that were deleted or commits that were overwritten with an <code>--amend<\/code> commit can be recovered (see <a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/git-scm.com\/book\/en\/v2\/ch00\/_data_recovery\">Data Recovery<\/a> for data recovery). However, <strong>anything you lose that was never committed is likely never to be seen again.<\/strong><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Commands-2\"><\/span>Commands<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h4><span class=\"ez-toc-section\" id=\"additional_commit\"><\/span>additional commit<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>When you commit too early and  possibly forget to add some files, or you mess up your commit message. Make the additional changes you forgot, stage them, and commit again using the <code>--amend<\/code> option.<\/p>\n<p>This command merge your last commit with what is changed after that as one. You end up with a single commit\u2009\u2014\u2009the second commit replaces the results of the first. The previous won&#8217;t show up in the repository history.<\/p>\n<p><strong>Only amend commits that are still local and have not been pushed somewhere.<\/strong><\/p>\n<pre><code class=\"language-Bash line-numbers\">git commit --amend\n<\/code><\/pre>\n<h4><span class=\"ez-toc-section\" id=\"unstage_files\"><\/span>unstage files<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>This command doesn&#8217;t unmodify changes in the file, but make the file unstaged for the following commit.<\/p>\n<pre><code class=\"language-bash line-numbers\">git reset HEAD &lt;filename&gt;\n#OR (in lastest version)\ngit restore --staged &lt;filename&gt;\n<\/code><\/pre>\n<h4><span class=\"ez-toc-section\" id=\"unmodifying_a_modified_file\"><\/span>unmodifying a modified file<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>discard changes made to files<\/p>\n<pre><code class=\"language-bash line-numbers\">git checkout -- &lt;filename&gt;\n#OR (in lastest version)\ngit restore &lt;filename&gt;\n<\/code><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Working_with_Remotes\"><\/span>Working with Remotes<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Remote repositories are versions of your project that are hosted on the  Internet or network somewhere. You can have several of them, each of which generally is either  read-only or read\/write for you. Collaborating with others involves managing these remote repositories  and pushing and pulling data to and from them when you need to share  work. Managing remote repositories includes knowing how to add remote  repositories, remove remotes that are no longer valid, manage various  remote branches and define them as being tracked or not, and more.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Commands-3\"><\/span>Commands<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h4><span class=\"ez-toc-section\" id=\"show_your_remotes\"><\/span>show your remotes<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<pre><code class=\"language-bash line-numbers\">git remote\n\n#show the URLS\ngit remote -V\n<\/code><\/pre>\n<h4><span class=\"ez-toc-section\" id=\"add_remote_repositories\"><\/span>add remote repositories<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<pre><code class=\"language-bash line-numbers\">git remote add &lt;remote_name&gt; [URL]\n<\/code><\/pre>\n<h4><span class=\"ez-toc-section\" id=\"fetch_and_pull\"><\/span>fetch and pull<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<pre><code class=\"language-bash line-numbers\">git fetch &lt;remote_repo&gt;\n\n#automatically fetch and merge\ngit pull &lt;remote_repo&gt;\n\n#fetch all branches at once\ngit pull &lt;remote_repo&gt; --all\n<\/code><\/pre>\n<h4><span class=\"ez-toc-section\" id=\"push_to_your_remotes\"><\/span>push to your remotes<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<pre><code class=\"language-R line-numbers\">#If local and remote have the same branch name\ngit push &lt;remote_repo&gt; BranchName\n\n#else\ngit push &lt;remote_repo&gt; localBranchName:remoteBranchName\n<\/code><\/pre>\n<p>This command works only if you cloned from a server to which you have  write access and if nobody has pushed in the meantime. If you and someone else clone at the same time and they push upstream  and then you push upstream, your push will rightly be rejected. You\u2019ll have to fetch their work first and incorporate it into yours  before you\u2019ll be allowed to push.<\/p>\n<h4><span class=\"ez-toc-section\" id=\"compare_two_repositories\"><\/span>compare two repositories<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<pre><code class=\"language-bash line-numbers\">git diff &lt;branch_name&gt; remotes\/&lt;remote_name&gt;\/branch_name\n<\/code><\/pre>\n<h4><span class=\"ez-toc-section\" id=\"inspect_a_remote\"><\/span>inspect a remote<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<pre><code class=\"language-bash line-numbers\">git remote show &lt;remote_repo&gt;\n<\/code><\/pre>\n<h4><span class=\"ez-toc-section\" id=\"rename_and_remove\"><\/span>rename and remove<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<pre><code class=\"language-bash line-numbers\">git remote rename &lt;old_name&gt; &lt;new_name&gt;\n\ngit remote remove &lt;remote_repo&gt;\n<\/code><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Branching\"><\/span>Branching<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>When you create a new branch, you create a new pointer to the same commit you\u2019re currently on. The special pointer HEAD points to the branch you&#8217;re currently on.<\/p>\n<p><img src=\"http:\/\/hongpanz.com\/wp-content\/uploads\/2022\/10\/image-20220927173452790.png\" alt=\"\" \/><\/p>\n<blockquote><p>\n  create a new pointer to the current commit\n<\/p><\/blockquote>\n<p><img src=\"http:\/\/hongpanz.com\/wp-content\/uploads\/2022\/10\/image-20220927165118024.png\" alt=\"\" \/><\/p>\n<blockquote><p>\n  move the HEAD pointer to testing branch\n<\/p><\/blockquote>\n<p><img src=\"http:\/\/hongpanz.com\/wp-content\/uploads\/2022\/10\/image-20220927165248108.png\" alt=\"\" \/><\/p>\n<blockquote><p>\n  HEAD pointer moves forward when you do a commit\n<\/p><\/blockquote>\n<p>Because a branch in Git is actually a simple file that contains the 40  character SHA-1 checksum of the commit it points to, branches are cheap  to create and destroy. Creating a new branch is as quick and simple as writing 41 bytes to a  file (40 characters and a newline).<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Commands-4\"><\/span>Commands<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h4><span class=\"ez-toc-section\" id=\"check_branches\"><\/span>check branches<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<pre><code class=\"language-bash line-numbers\">#check local branches\ngit branch\n\n#check local and remote branches\ngit branch -a\n<\/code><\/pre>\n<p>By default, git clone only pull the default branch down (e.g. master). <code>branch -a<\/code> command show all the hidden branch. Use <code>pull -all<\/code> command to pull down all the branches, or create a local tracking branch.<\/p>\n<pre><code class=\"language-bash line-numbers\">* master\n  remotes\/origin\/HEAD -&gt; origin\/master\n  remotes\/origin\/ROC_modified\n  remotes\/origin\/master\n<\/code><\/pre>\n<pre><code class=\"language-bash line-numbers\">#take a quick peek at an upstream branch, check it out directly\ngit checkout orgian\/&lt;branch_name&gt;\n\n#create a local tracking branch\ngit checkout &lt;branch_name&gt;\n<\/code><\/pre>\n<p><img src=\"http:\/\/hongpanz.com\/wp-content\/uploads\/2022\/10\/image-20220927173331165.png\" alt=\"\" \/><\/p>\n<h4><span class=\"ez-toc-section\" id=\"create_a_branch\"><\/span>create a branch<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<pre><code class=\"language-bash line-numbers\">git branch &lt;branch_name&gt;\n<\/code><\/pre>\n<h4><span class=\"ez-toc-section\" id=\"check_the_pointer\"><\/span>check the pointer<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p><code>git log<\/code> doesn\u2019t show <em>all<\/em> the branches <em>all<\/em> the time. By default, <code>git log<\/code> will only show commit history below the branch you\u2019ve checked out.<\/p>\n<pre><code class=\"language-bash line-numbers\">git log --oneline --decorate\n<\/code><\/pre>\n<h4><span class=\"ez-toc-section\" id=\"switch_branches\"><\/span>switch branches<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>It moved the HEAD pointer point to specific branch, and it reverted the files in your working directory back to the snapshot that branch points to.<\/p>\n<pre><code class=\"language-bash line-numbers\">git checkout &lt;branch_name&gt;\n#OR\ngit switch &lt;branch_name&gt;\n<\/code><\/pre>\n<h4><span class=\"ez-toc-section\" id=\"remove_branches\"><\/span>remove branches<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<pre><code class=\"language-bash line-numbers\">git branch --delete &lt;branch_name&gt;\n<\/code><\/pre>\n<h4><span class=\"ez-toc-section\" id=\"merge_branches\"><\/span>merge branches<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<pre><code class=\"language-R line-numbers\">#switch to the branch that is backward\ngit checkout branchA\n\n#branchA &lt;- branchB\ngit merge branchB\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Status of files Modified means that you have changed the file but have not committed it to your database yet. Staged means that you have marked a modified file in its current version to go into your next commit snapshot. Committed means that the data is safely stored in your local database. Untracked basically means [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[9],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/hongpanz.com\/index.php\/wp-json\/wp\/v2\/posts\/118"}],"collection":[{"href":"https:\/\/hongpanz.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hongpanz.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hongpanz.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hongpanz.com\/index.php\/wp-json\/wp\/v2\/comments?post=118"}],"version-history":[{"count":6,"href":"https:\/\/hongpanz.com\/index.php\/wp-json\/wp\/v2\/posts\/118\/revisions"}],"predecessor-version":[{"id":126,"href":"https:\/\/hongpanz.com\/index.php\/wp-json\/wp\/v2\/posts\/118\/revisions\/126"}],"wp:attachment":[{"href":"https:\/\/hongpanz.com\/index.php\/wp-json\/wp\/v2\/media?parent=118"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hongpanz.com\/index.php\/wp-json\/wp\/v2\/categories?post=118"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hongpanz.com\/index.php\/wp-json\/wp\/v2\/tags?post=118"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}