{"id":621,"date":"2021-07-23T12:34:11","date_gmt":"2021-07-23T12:34:11","guid":{"rendered":"https:\/\/ssdsunucum.com\/blog\/guide-to-git-common-git-commands\/"},"modified":"2021-07-23T12:34:11","modified_gmt":"2021-07-23T12:34:11","slug":"guide-to-git-common-git-commands","status":"publish","type":"post","link":"https:\/\/ssdsunucum.com\/blog\/guide-to-git-common-git-commands\/","title":{"rendered":"Guide to Git\u2122 &#8211; Common Git Commands"},"content":{"rendered":"<\/p>\n<div class=\"col-md-9\">\n<div class=\"flex-column flex-md-row article-header\"><\/div>\n<hr>\n<h2 id=\"overview\">Overview<\/h2>\n<p>You can access all of Git\u2122\u2019s functionality via the command line. This document lists common commands and options that may assist you when you learn Git.<\/p>\n<div class=\"callout callout-warning\">\n<div class=\"callout-heading\">Important:<\/div>\n<div class=\"callout-content\">\n<ul>\n<li>\n<p>This document is <strong>not<\/strong> comprehensive. It intentionally omits information about intermediate and advanced Git functionality. For more information about additional commands and options, read Git\u2019s documentation.<\/p>\n<\/li>\n<li>\n<p>The terminology in this document assumes basic familiarity with the command line.<\/p>\n<\/li>\n<\/ul><\/div>\n<\/div>\n<h2 id=\"common-git-commands\">Common Git commands<\/h2>\n<div class=\"callout callout-info\">\n<div class=\"callout-heading\">Note:<\/div>\n<div class=\"callout-content\">\n<ul>\n<li>\n<p>To resolve Git errors, read our Guide to Git &#8211; For System Administrators documentation.<\/p>\n<\/li>\n<li>\n<p>For general Linux commands, read our Getting Started with Linux Commands documentation.<\/p>\n<\/li>\n<li>\n<p>For help to access the command line in order to run these commands, read our How to Access the Command Line documentation.<\/p>\n<\/li>\n<li>\n<p>You can add the <code>--help<\/code> option to any Git command in order to view the manual page for that command.<\/p>\n<\/li>\n<\/ul><\/div>\n<\/div>\n<h3 id=\"git-clone\">git clone<\/h3>\n<p>This command clones a repository into a new directory, creates remote-tracking branches, and forks a new working branch from the cloned repository\u2019s active branch.<\/p>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-perl\" data-lang=\"perl\">git clone repositoryurl<\/code><\/pre>\n<\/div>\n<p>In the example above, <code>repositoryurl<\/code> represents the URL of the repository that you wish to clone.<\/p>\n<div class=\"callout callout-info\">\n<div class=\"callout-heading\">Note:<\/div>\n<div class=\"callout-content\">\n<ul>\n<li>Use the <code>git fetch<\/code> command to update the new repository\u2019s remote-tracking branches.<\/li>\n<li>Use the <code>git pull<\/code> command to merge the remote master branch into the current master branch.<\/li>\n<li>cPanel\u2019s <em>Git\u2122 Version Control<\/em> interface (<em>cPanel &gt;&gt; Home &gt;&gt; Files &gt;&gt; Git\u2122 Version Control<\/em>) provides the URL to use to clone each of your account\u2019s repositories.<\/li>\n<li>To clone private repositories, you must perform additional steps. For more information, read our Guide to Git &#8211; Set Up Access to Private Repositories documentation.<\/li>\n<\/ul><\/div>\n<\/div>\n<h3 id=\"git-add\">git add<\/h3>\n<p>This command adds the current version of a file to the index of staged content for the next commit.<\/p>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-perl\" data-lang=\"perl\">git add [options] filepath<\/code><\/pre>\n<\/div>\n<p>In the example above, <code>filepath<\/code> represents the file\u2019s absolute path <strong>or<\/strong> its path relative to the current working directory.<\/p>\n<ul>\n<li>\n<p>To stage uncommitted changes for <strong>all<\/strong> tracked files, run this command with either of the <code>-a<\/code> or <code>-u<\/code> options (and without a specified file path).<\/p>\n<\/li>\n<li>\n<p>This command <strong>only<\/strong> stages the current changes for the current commit. The next time that you create a commit, you <strong>must<\/strong> run the command for the file again in order to stage any new changes.<\/p>\n<\/li>\n<\/ul>\n<h3 id=\"git-commit\">git commit<\/h3>\n<p>This command creates a new commit for the currently-staged changes.<\/p>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-perl\" data-lang=\"perl\">git commit [options]<\/code><\/pre>\n<\/div>\n<p>When you run this command (without the <code>-m<\/code> option), Git immediately displays a text file, in which you can enter and save your commit message.<\/p>\n<ul>\n<li>\n<p>To automatically stage modified and deleted files before Git creates the commit, run this command with the <code>-a<\/code> option.<\/p>\n<\/li>\n<li>\n<p>To specify a short commit message directly from the command line, run this command with the <code>-m<\/code> option. For example:<\/p>\n<\/li>\n<\/ul>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-perl\" data-lang=\"perl\">git commit <span style=\"color:#f92672\">-<\/span>m <span style=\"color:#e6db74\">\"Commit message here.\"<\/span><\/code><\/pre>\n<\/div>\n<div class=\"callout callout-info\">\n<div class=\"callout-heading\">Note:<\/div>\n<div class=\"callout-content\">\n<p>To stage changes for inclusion in a commit, use the <code>git add<\/code> or <code>git rm<\/code> commands or provide individual filepaths as arguments to this command.<\/p>\n<\/p><\/div>\n<\/div>\n<h3 id=\"git-checkout\">git checkout<\/h3>\n<p>This command sets the specified branch as the current working branch.<\/p>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-perl\" data-lang=\"perl\">git checkout [options] branchname<\/code><\/pre>\n<\/div>\n<p>In the example above, <code>branchname<\/code> represents the branch to check out.<\/p>\n<ul>\n<li>\n<p>To check out only a specified file, run this command with a file path instead of a branch name.\n<\/p>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-perl\" data-lang=\"perl\">git checkout mybranch files<span style=\"color:#e6db74\">\/templates\/<\/span><span style=\"color:#ae81ff\">2<\/span><span style=\"color:#f92672\">.<\/span>html<\/code><\/pre>\n<\/div>\n<p>In this example, <code>mybranch<\/code> represents the branch that contains the version of the file that you wish to check out and <code>files\/templates\/2.html<\/code> represents the file to check out. If you run this command, the system will replace the <code>files\/templates\/2.html<\/code> file\u2019s contents in the current local working branch with the file\u2019s contents from the <code>mybranch<\/code> branch.<\/p>\n<div class=\"callout callout-info\">\n<div class=\"callout-heading\">Note:<\/div>\n<div class=\"callout-content\">\n<p>If you omit the branch name, Git will check out that file from the HEAD of the current branch.<\/p>\n<\/p><\/div>\n<\/div>\n<\/li>\n<li>\n<p>To create a new branch with the specified branch name and then check it out, run this command with the <code>-b<\/code> option.<\/p>\n<\/li>\n<li>\n<p>To forcibly change branches, run the command with the <code>-f<\/code> option. This option causes Git to overwrite local changes in order to match the working tree to the branch\u2019s HEAD commit.<\/p>\n<\/li>\n<\/ul>\n<h3 id=\"git-rm\">git rm<\/h3>\n<p>This command removes files or directories from Git\u2019s index and working tree.<\/p>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-perl\" data-lang=\"perl\">git rm [options] files_or_dirs<\/code><\/pre>\n<\/div>\n<p>In the example above, <code>files_or_dirs<\/code> represents the paths to the files or directories to remove, relative to the repository\u2019s main directory.<\/p>\n<div class=\"callout callout-warning\">\n<div class=\"callout-heading\">Important:<\/div>\n<div class=\"callout-content\">\n<ul>\n<li>\n<p>To run this command, the specified file <strong>cannot<\/strong> contain uncommitted changes.<\/p>\n<\/li>\n<li>\n<p>This command <strong>cannot<\/strong> retain the file in the index <strong>and<\/strong> remove the file from the working tree. To do this, use BASH\u2019s <code>rm<\/code> command.<\/p>\n<\/li>\n<li>\n<p>If you specify a directory name, you <strong>must<\/strong> also use the <code>-r<\/code> option. This option allows the command to recursively remove the files in that directory.<\/p>\n<\/li>\n<\/ul><\/div>\n<\/div>\n<h3 id=\"git-fetch\">git fetch<\/h3>\n<p>This command downloads branches, tags, and their histories from one or more other repositories.<\/p>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-perl\" data-lang=\"perl\">git fetch [options] remotename<\/code><\/pre>\n<\/div>\n<p>In the example above, <code>remotename<\/code> represents the name of the remote repository.<\/p>\n<h3 id=\"git-pull\">git pull<\/h3>\n<p>This command fetches and merges changes from a local branch or a remote or local repository. With most options, this command combines the <code>git fetch<\/code> and <code>git merge<\/code> commands.<\/p>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-perl\" data-lang=\"perl\">git pull [options] repo<span style=\"color:#f92672\">-<\/span><span style=\"color:#f92672\">or<\/span><span style=\"color:#f92672\">-<\/span>branch<\/code><\/pre>\n<\/div>\n<p>In the example above, <code>repo-or-branch<\/code> represents the branch name or the repository name or URL.<\/p>\n<h3 id=\"git-push\">git push<\/h3>\n<p>This command adds your committed changes to the specified repository and branch.<\/p>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-perl\" data-lang=\"perl\">git push [options] repository branch<\/code><\/pre>\n<\/div>\n<p>In the example above, <code>repository<\/code> represents the repository name or URL and <code>branch<\/code> represents the remote branch on that repository.<\/p>\n<ul>\n<li>\n<p>If you do <strong>not<\/strong> specify a repository, the command performs one of the following actions:<\/p>\n<ul>\n<li>If your current branch\u2019s configuration includes a remote repository, the command adds your changes to that repository.<\/li>\n<li>If your current branch\u2019s configuration does <strong>not<\/strong> include a remote repository, the command adds your changes to the <code>origin<\/code> repository.\n<div class=\"callout callout-warning\">\n<div class=\"callout-heading\">Important:<\/div>\n<div class=\"callout-content\">\n<p>You <strong>must<\/strong> explicitly specify a repository in order to specify a branch. If you do <strong>not<\/strong> specify a branch, the command adds your changes to the remote repository\u2019s current branch.<\/p>\n<\/p><\/div>\n<\/div>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>To push <strong>all<\/strong> commits from <strong>all<\/strong> local branches to their upstream repositories, run this command with the <code>--all<\/code> option.<\/p>\n<\/li>\n<li>\n<p>To add the specified repository to the branch as its upstream repository, run this command with the <code>--set-upstream<\/code> option.<\/p>\n<ul>\n<li>This allows you to omit the repository on subsequent pushes to upstream.<\/li>\n<li>You must specify a remote repository when you use this option.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<div class=\"callout callout-info\">\n<div class=\"callout-heading\">Note:<\/div>\n<div class=\"callout-content\">\n<p>cPanel\u2019s cPanel\u2019s <em>Git\u2122 Version Control<\/em> interface (<em>cPanel &gt;&gt; Home &gt;&gt; Files &gt;&gt; Git\u2122 Version Control<\/em>) automatically adds a <code>post-receive<\/code> hook that each push to cPanel-managed repositories triggers. For more information, read our Guide to Git &#8211; Deployment documentation or Git\u2019s githooks documentation.<\/p>\n<\/p><\/div>\n<\/div>\n<h3 id=\"git-branch\">git branch<\/h3>\n<p>This command creates, lists, or deletes branches.<\/p>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-perl\" data-lang=\"perl\">git branch [options] branchname<\/code><\/pre>\n<\/div>\n<p>In the example above, <code>branchname<\/code> represents the branch name.<\/p>\n<ul>\n<li>\n<p>To create a new branch, run this command with the desired branch name.<\/p>\n<div class=\"callout callout-warning\">\n<div class=\"callout-heading\">Important:<\/div>\n<div class=\"callout-content\">\n<p>Git does <strong>not<\/strong> automatically check out new branches when you create them. You <strong>must<\/strong> also run the <code>git checkout<\/code> command in order to check out your new branch.<\/p>\n<\/p><\/div>\n<\/div>\n<\/li>\n<li>\n<p>To retrieve a list of existing local branches, run this command without a branch name. Use the <code>-a<\/code> option to retrieve a list of both local and remote branches.<\/p>\n<\/li>\n<li>\n<p>To set the upstream branch for a specified branch, run this command with the <code>-u<\/code> option.<\/p>\n<\/li>\n<li>\n<p>To rename a specified branch, run this command with the <code>-m<\/code> option and the current and new branch names. For example:\n<\/p>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-perl\" data-lang=\"perl\">git branch <span style=\"color:#f92672\">-<\/span>m oldbranch newbranch<\/code><\/pre>\n<\/div>\n<p>In this example, <code>oldbranch<\/code> represents the current branch name and <code>newbranch<\/code> represents the new branch name.<\/li>\n<li>\n<p>To delete a specified branch, run this command with the <code>-d<\/code> option.<\/p>\n<\/li>\n<\/ul>\n<h3 id=\"git-merge\">git merge<\/h3>\n<p>This command combines the history of one or more commits into the history of the current branch.<\/p>\n<\/p>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-perl\" data-lang=\"perl\">git merge [options]<\/code><\/pre>\n<\/div>\n<div class=\"callout callout-info\">\n<div class=\"callout-heading\">Note:<\/div>\n<div class=\"callout-content\">\n<p>The <code>git pull<\/code> command automatically performs this action.<\/p>\n<\/p><\/div>\n<\/div>\n<h3 id=\"git-blame\">git blame<\/h3>\n<p>This command displays the specified file with the author, most-recent change date, and commit SHA-1 for each line of the file.<\/p>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-perl\" data-lang=\"perl\">git blame [options] filepath<\/code><\/pre>\n<\/div>\n<p>In the example above, <code>filepath<\/code> represents the file\u2019s absolute path or its path relative to the current working directory.<\/p>\n<p>When you run this command without additional options, the output will resemble the following example:<\/p>\n<div class=\"highlight\">\n<div style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\">\n<table style=\"border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;\">\n<tr>\n<td style=\"vertical-align:top;padding:0;margin:0;border:0;\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-go\" data-lang=\"go\"><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">1\n<\/span><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">2\n<\/span><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">3\n<\/span><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">4\n<\/span><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">5\n<\/span><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">6\n<\/span><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">7\n<\/span><\/code><\/pre>\n<\/td>\n<td style=\"vertical-align:top;padding:0;margin:0;border:0;;width:100%\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-go\" data-lang=\"go\"><span style=\"color:#ae81ff\">5<\/span><span style=\"color:#a6e22e\">f033c48d84a<\/span> (<span style=\"color:#a6e22e\">Jane<\/span> <span style=\"color:#a6e22e\">E<\/span>. <span style=\"color:#a6e22e\">Coder<\/span>        <span style=\"color:#ae81ff\">2017<\/span><span style=\"color:#f92672\">-<\/span><span style=\"color:#ae81ff\">05<\/span><span style=\"color:#f92672\">-<\/span><span style=\"color:#ae81ff\">24<\/span> <span style=\"color:#ae81ff\">18<\/span>:<span style=\"color:#ae81ff\">25<\/span>:<span style=\"color:#ae81ff\">53<\/span> <span style=\"color:#f92672\">-<\/span><span style=\"color:#ae81ff\">0600<\/span>  <span style=\"color:#ae81ff\">1<\/span>) &lt;!<span style=\"color:#a6e22e\">DOCTYPE<\/span> <span style=\"color:#a6e22e\">HTML<\/span>&gt;\n<span style=\"color:#ae81ff\">5<\/span><span style=\"color:#a6e22e\">f033c48d84a<\/span> (<span style=\"color:#a6e22e\">Jane<\/span> <span style=\"color:#a6e22e\">E<\/span>. <span style=\"color:#a6e22e\">Coder<\/span>        <span style=\"color:#ae81ff\">2017<\/span><span style=\"color:#f92672\">-<\/span><span style=\"color:#ae81ff\">05<\/span><span style=\"color:#f92672\">-<\/span><span style=\"color:#ae81ff\">24<\/span> <span style=\"color:#ae81ff\">18<\/span>:<span style=\"color:#ae81ff\">25<\/span>:<span style=\"color:#ae81ff\">53<\/span> <span style=\"color:#f92672\">-<\/span><span style=\"color:#ae81ff\">0600<\/span>  <span style=\"color:#ae81ff\">2<\/span>) &lt;<span style=\"color:#a6e22e\">html<\/span>&gt;\n<span style=\"color:#ae81ff\">5<\/span><span style=\"color:#a6e22e\">f033c48d84a<\/span> (<span style=\"color:#a6e22e\">Jane<\/span> <span style=\"color:#a6e22e\">E<\/span>. <span style=\"color:#a6e22e\">Coder<\/span>        <span style=\"color:#ae81ff\">2017<\/span><span style=\"color:#f92672\">-<\/span><span style=\"color:#ae81ff\">05<\/span><span style=\"color:#f92672\">-<\/span><span style=\"color:#ae81ff\">24<\/span> <span style=\"color:#ae81ff\">18<\/span>:<span style=\"color:#ae81ff\">25<\/span>:<span style=\"color:#ae81ff\">53<\/span> <span style=\"color:#f92672\">-<\/span><span style=\"color:#ae81ff\">0600<\/span>  <span style=\"color:#ae81ff\">3<\/span>)\n<span style=\"color:#ae81ff\">5<\/span><span style=\"color:#a6e22e\">f033c48d84a<\/span> (<span style=\"color:#a6e22e\">Jane<\/span> <span style=\"color:#a6e22e\">E<\/span>. <span style=\"color:#a6e22e\">Coder<\/span>        <span style=\"color:#ae81ff\">2017<\/span><span style=\"color:#f92672\">-<\/span><span style=\"color:#ae81ff\">05<\/span><span style=\"color:#f92672\">-<\/span><span style=\"color:#ae81ff\">24<\/span> <span style=\"color:#ae81ff\">18<\/span>:<span style=\"color:#ae81ff\">25<\/span>:<span style=\"color:#ae81ff\">53<\/span> <span style=\"color:#f92672\">-<\/span><span style=\"color:#ae81ff\">0600<\/span>  <span style=\"color:#ae81ff\">4<\/span>) &lt;<span style=\"color:#a6e22e\">body<\/span>&gt;\n<span style=\"color:#ae81ff\">54222e949682<\/span> (<span style=\"color:#a6e22e\">John<\/span> <span style=\"color:#a6e22e\">B<\/span>. <span style=\"color:#a6e22e\">Developer<\/span>    <span style=\"color:#ae81ff\">2018<\/span><span style=\"color:#f92672\">-<\/span><span style=\"color:#ae81ff\">01<\/span><span style=\"color:#f92672\">-<\/span><span style=\"color:#ae81ff\">08<\/span> <span style=\"color:#ae81ff\">10<\/span>:<span style=\"color:#ae81ff\">57<\/span>:<span style=\"color:#ae81ff\">07<\/span> <span style=\"color:#f92672\">+<\/span><span style=\"color:#ae81ff\">0000<\/span>  <span style=\"color:#ae81ff\">5<\/span>)    &lt;<span style=\"color:#a6e22e\">p<\/span>&gt;<span style=\"color:#a6e22e\">Here<\/span><span style=\"color:#960050;background-color:#1e0010\">'<\/span><span style=\"color:#a6e22e\">s<\/span> <span style=\"color:#a6e22e\">some<\/span> <span style=\"color:#a6e22e\">text<\/span>.&lt;<span style=\"color:#f92672\">\/<\/span><span style=\"color:#a6e22e\">p<\/span>&gt;\n<span style=\"color:#ae81ff\">5<\/span><span style=\"color:#a6e22e\">f033c48d84a<\/span> (<span style=\"color:#a6e22e\">Jane<\/span> <span style=\"color:#a6e22e\">E<\/span>. <span style=\"color:#a6e22e\">Coder<\/span>        <span style=\"color:#ae81ff\">2017<\/span><span style=\"color:#f92672\">-<\/span><span style=\"color:#ae81ff\">05<\/span><span style=\"color:#f92672\">-<\/span><span style=\"color:#ae81ff\">24<\/span> <span style=\"color:#ae81ff\">18<\/span>:<span style=\"color:#ae81ff\">25<\/span>:<span style=\"color:#ae81ff\">53<\/span> <span style=\"color:#f92672\">-<\/span><span style=\"color:#ae81ff\">0600<\/span>  <span style=\"color:#ae81ff\">6<\/span>)\n<span style=\"color:#ae81ff\">5<\/span><span style=\"color:#a6e22e\">f033c48d84a<\/span> (<span style=\"color:#a6e22e\">Jane<\/span> <span style=\"color:#a6e22e\">E<\/span>. <span style=\"color:#a6e22e\">Coder<\/span>        <span style=\"color:#ae81ff\">2017<\/span><span style=\"color:#f92672\">-<\/span><span style=\"color:#ae81ff\">05<\/span><span style=\"color:#f92672\">-<\/span><span style=\"color:#ae81ff\">24<\/span> <span style=\"color:#ae81ff\">18<\/span>:<span style=\"color:#ae81ff\">25<\/span>:<span style=\"color:#ae81ff\">53<\/span> <span style=\"color:#f92672\">-<\/span><span style=\"color:#ae81ff\">0600<\/span>  <span style=\"color:#ae81ff\">7<\/span>) &lt;<span style=\"color:#a6e22e\">script<\/span>&gt;<\/code><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<\/div>\n<\/div>\n<p>In this example, on May 24th, 2017, Jane E. Coder committed changes to the file. On January 8th, 2018, John B. Developer committed changes to the file. Because John committed changes after Jane, this output does <strong>not<\/strong> display any changes that Jane made to line 5 <strong>or<\/strong> the history of the other lines before Jane\u2019s commit.<\/p>\n<h3 id=\"git-clean\">git clean<\/h3>\n<p>This command removes untracked files (files that Git does not manage) from the working tree.<\/p>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-perl\" data-lang=\"perl\">git clean [options]<\/code><\/pre>\n<\/div>\n<ul>\n<li>\n<p>To display a list of untracked files to remove but <strong>not<\/strong> remove them, run this command with the <code>-n<\/code> option.<\/p>\n<\/li>\n<li>\n<p>To also remove untracked directories, run this command with the <code>-d<\/code> option.<\/p>\n<\/li>\n<\/ul>\n<h3 id=\"git-config\">git config<\/h3>\n<p>This command retrieves or updates Git\u2019s global and repository settings in its configuration files.<\/p>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-perl\" data-lang=\"perl\">git config [options]<\/code><\/pre>\n<\/div>\n<p>Git stores your settings in the following files:<\/p>\n<ul>\n<li><code>\/path-to-git\/etc\/gitconfig<\/code> \u2014 Global settings.<\/li>\n<li><code>\/path-to-git\/config<\/code> \u2014 Repository settings.<\/li>\n<li><code>\/home-directory\/.gitconfig<\/code> \u2014 A user configuration file.<\/li>\n<li><code>\/home-directory\/.config\/git\/config<\/code> \u2014 A user configuration file.<\/li>\n<\/ul>\n<div class=\"callout callout-info\">\n<div class=\"callout-heading\">Note:<\/div>\n<div class=\"callout-content\">\n<ul>\n<li>In the paths above, <code>path-to-git<\/code> represents the Git installation\u2019s absolute path and <code>home-directory<\/code> represents a cPanel account\u2019s home directory (for example, the <code>\/home\/user\/.gitconfig<\/code> file).<\/li>\n<li>If both user configuration files exist and their values conflict, the system uses the values in the <code>.gitconfig<\/code> file.<\/li>\n<li>This command accepts many options for each of Git\u2019s configurable settings. To use this command, read Git\u2019s git config documentation.<\/li>\n<\/ul><\/div>\n<\/div>\n<h3 id=\"git-diff\">git diff<\/h3>\n<p>This command compares changes between two commits, a commit and the current working tree, two branches or working trees, or two files.<\/p>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-perl\" data-lang=\"perl\">git diff [options]<\/code><\/pre>\n<\/div>\n<p>By default, this command returns a comparison of the working tree and your last commit (the changes that Git would commit if you ran the <code>git commit -a<\/code> command).<\/p>\n<p>You may wish to use the following common options:<\/p>\n<ul>\n<li>\n<p>To view a comparison of two branches, run the following command, where <code>branch1<\/code> and <code>branch2<\/code> represent the branches to compare:\n<\/p>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-perl\" data-lang=\"perl\">git diff branch1<span style=\"color:#f92672\">..<\/span>branch2<\/code><\/pre>\n<\/div>\n<\/li>\n<li>\n<p>To view a comparison of two commits, run the following command, where <code>FirstSHA<\/code> and <code>SecondSHA<\/code> represent the SHA-1 values for the two commits:\n<\/p>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-perl\" data-lang=\"perl\">git diff FirstSHA<span style=\"color:#f92672\">..<\/span>SecondSHA<\/code><\/pre>\n<\/div>\n<\/li>\n<li>\n<p>To only view differences between two versions of one file in a working tree, branch, or commit, specify that filepath as an argument. For example:\n<\/p>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-perl\" data-lang=\"perl\">git diff branch1<span style=\"color:#f92672\">..<\/span>branch2 filename<\/code><\/pre>\n<\/div>\n<p>In the example above, <code>branch1<\/code> and <code>branch2<\/code> represent the branches from which Git will compare the contents of the <code>filename<\/code> file.<\/li>\n<\/ul>\n<h3 id=\"git-grep\">git grep<\/h3>\n<p>This command searches the current working tree for one or more patterns (generally, strings or regular expressions).<\/p>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-perl\" data-lang=\"perl\">git grep [options] <span style=\"color:#e6db74\">\"pattern\"<\/span><\/code><\/pre>\n<\/div>\n<p>In the example above, <code>pattern<\/code> represents the data to query.<\/p>\n<ul>\n<li>\n<p>To perform a case-insensitive search, run this command with the <code>-i<\/code> option.<\/p>\n<\/li>\n<li>\n<p>To use Perl-Compatible Regular Expressions (PCREs) in your patterns, run this command with the <code>--perl-regexp<\/code> option. cPanel &#038; WHM\u2019s implementation of Git automatically includes the necessary dependencies for this option.<\/p>\n<\/li>\n<li>\n<p>To return only files that include all of the specified patterns (when you run the command with multiple patterns), run this command with the <code>--all-match<\/code> option. For example:\n<\/p>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-perl\" data-lang=\"perl\">git grep <span style=\"color:#f92672\">--<\/span>all<span style=\"color:#f92672\">-<\/span>match <span style=\"color:#e6db74\">\"string one\"<\/span> <span style=\"color:#e6db74\">\"string two\"<\/span> <span style=\"color:#e6db74\">\"string three\"<\/span><\/code><\/pre>\n<\/div>\n<p>This example would return files that contain <code>string one<\/code>, <code>string two<\/code>, <strong>and<\/strong> <code>string three<\/code>, but would <strong>not<\/strong> return files that only contain <code>string two<\/code>.<\/li>\n<li>\n<p>To return file paths relative to the repository\u2019s main directory rather than the current directory, run this command with the <code>--full-name<\/code> option.<\/p>\n<\/li>\n<\/ul>\n<h3 id=\"git-log\">git log<\/h3>\n<p>This command queries the commit logs for your current branch.<\/p>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-perl\" data-lang=\"perl\">git log [options]<\/code><\/pre>\n<\/div>\n<ul>\n<li>\n<p>To view only results from a specific range of commits, run the following command:\n<\/p>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-perl\" data-lang=\"perl\">git log FirstSHA<span style=\"color:#f92672\">..<\/span>SecondSHA<\/code><\/pre>\n<\/div>\n<p>In this example, <code>FirstSHA<\/code> and <code>SecondSHA<\/code> represent the SHA-1 values for the two commits.<\/p>\n<div class=\"callout callout-info\">\n<div class=\"callout-heading\">Note:<\/div>\n<div class=\"callout-content\">\n<p>If you do not specify a range of commits to query, this command queries all commits between the <code>origin<\/code> commit and HEAD for the current branch.<\/p>\n<\/p><\/div>\n<\/div>\n<\/li>\n<li>\n<p>To view only a specific number of the most recent log entries, run the following command, where <code>num<\/code> represents the number of entries to return:\n<\/p>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-perl\" data-lang=\"perl\">git log <span style=\"color:#f92672\">-<\/span>num<\/code><\/pre>\n<\/div>\n<\/li>\n<li>\n<p>To view only log entries before or after a specific date, run one of the following commands, where <code>date<\/code> represents the specified date:\n<\/p>\n<div class=\"highlight\">\n<div style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\">\n<table style=\"border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;\">\n<tr>\n<td style=\"vertical-align:top;padding:0;margin:0;border:0;\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-go\" data-lang=\"go\"><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">1\n<\/span><span style=\"margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f\">2\n<\/span><\/code><\/pre>\n<\/td>\n<td style=\"vertical-align:top;padding:0;margin:0;border:0;;width:100%\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-go\" data-lang=\"go\"><span style=\"color:#a6e22e\">git<\/span> <span style=\"color:#a6e22e\">log<\/span> <span style=\"color:#f92672\">--<\/span><span style=\"color:#a6e22e\">before<\/span>=<span style=\"color:#a6e22e\">date<\/span>\n<span style=\"color:#a6e22e\">git<\/span> <span style=\"color:#a6e22e\">log<\/span> <span style=\"color:#f92672\">--<\/span><span style=\"color:#a6e22e\">after<\/span>=<span style=\"color:#a6e22e\">date<\/span><\/code><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<\/div>\n<\/div>\n<p>For date formatting options, read Git\u2019s git log documentation.<\/li>\n<li>\n<p>To view only log entries for commits from a specific author, run the following command, where <code>authorname<\/code> represents the author\u2019s name in their <code>.gitconfig<\/code> file:\n<\/p>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-perl\" data-lang=\"perl\">git log <span style=\"color:#f92672\">--<\/span>author<span style=\"color:#f92672\">=<\/span>authorname<\/code><\/pre>\n<\/div>\n<\/li>\n<li>\n<p>To view only log entries that contain a specific pattern (generally, a string), run the following command, where <code>pattern<\/code> represents the pattern to query:\n<\/p>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-perl\" data-lang=\"perl\">git log <span style=\"color:#f92672\">--<\/span>grep<span style=\"color:#f92672\">=<\/span>pattern<\/code><\/pre>\n<\/div>\n<p>If you include multiple patterns to query, use the <code>--all-match<\/code> option to limit output to log entries that match <strong>all<\/strong> of the specified patterns.<\/li>\n<\/ul>\n<div class=\"callout callout-info\">\n<div class=\"callout-heading\">Note:<\/div>\n<div class=\"callout-content\">\n<ul>\n<li>This command also accepts formatting options from the <code>git diff<\/code> command.<\/li>\n<li>If you only require summarized commit log information, you may wish to use the <code>git shortlog<\/code> command.<\/li>\n<\/ul><\/div>\n<\/div>\n<h3 id=\"git-revert\">git revert<\/h3>\n<p>This command reverts existing commits within a specified range and then allows you to edit their commit messages.<\/p>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-perl\" data-lang=\"perl\">git revert [options] commit1<span style=\"color:#f92672\">..<\/span>commit2<\/code><\/pre>\n<\/div>\n<p>In the example above, <code>commit1<\/code> and <code>commit2<\/code> represent the SHA-1 values for the range of commits to revert.<\/p>\n<div class=\"callout callout-warning\">\n<div class=\"callout-heading\">Important:<\/div>\n<div class=\"callout-content\">\n<p>To run this command, your working tree <strong>cannot<\/strong> contain uncommitted changes.<\/p>\n<\/p><\/div>\n<\/div>\n<h3 id=\"git-shortlog\">git shortlog<\/h3>\n<p>This command produces a shortened version of the output of the <code>git log<\/code> command. You may wish to use this command if, for example, you need to generate a list of changes for release notes or a change log.<\/p>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-perl\" data-lang=\"perl\">git shortlog [options]<\/code><\/pre>\n<\/div>\n<h3 id=\"git-stash\">git stash<\/h3>\n<p>This command uses several options to create, manage, and retrieve sets of changes (stashes). When you run this command without specified options, it defaults to <code>git stash<\/code> save functionality.<\/p>\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-perl\" data-lang=\"perl\">git stash [options]<\/code><\/pre>\n<\/div>\n<p>Use the following options to manage stashes:<\/p>\n<ul>\n<li>To create a new stash and return the current branch to its state in the <code>HEAD<\/code> commit, run this command with the <code>save<\/code> option. When you use this option, you can also use the <code>-message<\/code> option to add a description to the stash. For example:\n<div class=\"highlight\">\n<pre style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-perl\" data-lang=\"perl\">git stash save <span style=\"color:#f92672\">-<\/span>message <span style=\"color:#e6db74\">\"Description\"<\/span><\/code><\/pre>\n<\/div>\n<p>In the example above, <code>Description<\/code> represents the stash description.<\/li>\n<li>To return a comparison of stashed changes with the <code>HEAD<\/code> commit when you created the stash, run this command with the <code>show mystash<\/code> option.<\/li>\n<li>To list your current stashes, run this command with the <code>list<\/code> option.<\/li>\n<li>To apply stashed changes to the current working tree and and remove the stash, run this command with the <code>pop mystash<\/code> option.<\/li>\n<li>To apply stashed changes to the current working tree but <strong>not<\/strong> remove the stash, run this command with the <code>apply mystash<\/code> option.<\/li>\n<li>To remove all stashes, run this command with the <code>clear<\/code> option.<\/li>\n<\/ul>\n<div class=\"callout callout-info\">\n<div class=\"callout-heading\">Note:<\/div>\n<div class=\"callout-content\">\n<p>In the options above, <code>mystash<\/code> represents the reflog entry or stash index for the desired stashed changes.<\/p>\n<\/p><\/div>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Overview You can access all of Git\u2122\u2019s functionality via the command line. This document lists common commands and options that may assist you when you learn Git. Important: This document is not comprehensive. It intentionally omits information about intermediate and advanced Git functionality. For more information about additional commands and options, read Git\u2019s documentation. The &hellip;<\/p>\n","protected":false},"author":1,"featured_media":622,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/posts\/621"}],"collection":[{"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/comments?post=621"}],"version-history":[{"count":0,"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/posts\/621\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/media\/622"}],"wp:attachment":[{"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/media?parent=621"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/categories?post=621"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ssdsunucum.com\/blog\/wp-json\/wp\/v2\/tags?post=621"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}