{"id":6754,"date":"2019-03-16T18:06:42","date_gmt":"2019-03-16T18:06:42","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=6754"},"modified":"2019-03-16T18:06:42","modified_gmt":"2019-03-16T18:06:42","slug":"git-aliases","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/git-aliases\/","title":{"rendered":"Git aliases"},"content":{"rendered":"<p>In a previous post on git (<a href=\"http:\/\/putridparrot.com\/blog\/using-git-from-the-cli\/\" rel=\"noopener noreferrer\" target=\"_blank\">Using GIT from the CLI<\/a>), I listed a fair few commands which are very useful. For the most part they&#8217;re fairly simple commands\/options, but occasionally they become less easy to remember.<\/p>\n<p>For example to check for merge conflicts on a branch that you may wish to merge master to, you can type<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\ngit merge master --no-ff --no-commit\r\n<\/pre>\n<p>Luckily I have this blog post allowing me to copy and paste this command, an alternate might be to create an alias to this command. <\/p>\n<p><strong>Adding an alias<\/strong><\/p>\n<p>Creating the alias is simply a way to store a command name within git&#8217;s global config which runs another command. Whether we want to simply shorten a name, like using <em>co<\/em> and ci<\/em> in place of <em>checkout<\/em> and <em>commit<\/em> or shorten a command such as the <em>merge<\/em> above with <em>check-conflicts<\/em>.<\/p>\n<p>To create an alias we use the following<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\ngit config --global alias.check-conflicts 'merge master --no-ff --no-commit'\r\n<\/pre>\n<p>In this example we&#8217;re telling git to add configuration using &#8211;global option (so the configuration is across all repositories or &#8211;local for just this repository). We create the alias using the <em>alias<\/em> option followed by a period\/full stop and then the name we want for our alias. This is then followed by the git command and options (within single or double quotes if there are multiple options). <\/p>\n<p>Now we can execute<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\ngit check-conflicts\r\n<\/pre>\n<p><strong>Deleting an Alias<\/strong><\/p>\n<p>To delete an alias we can either remove it from the config file (for example .gitconfig) or run the following command line<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\ngit config --global --unset alias.check-conflicts\r\n<\/pre>\n<p><strong>Listing Aliases<\/strong><\/p>\n<p>We can look in the .gitconfig or run the following command line to list the available aliases<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\ngit config --get-regexp '^alias\\.'\r\n<\/pre>\n<p><strong>Creating an Alias to list Aliases<\/strong><\/p>\n<p>To round this up nicely, let&#8217;s now create an alias to list aliases, for example<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\ngit config --global alias.alias &quot;config --get-regexp ^alias\\.&quot;\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In a previous post on git (Using GIT from the CLI), I listed a fair few commands which are very useful. For the most part they&#8217;re fairly simple commands\/options, but occasionally they become less easy to remember. For example to check for merge conflicts on a branch that you may wish to merge master to, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[206],"tags":[],"class_list":["post-6754","post","type-post","status-publish","format-standard","hentry","category-git-2"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/6754","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=6754"}],"version-history":[{"count":3,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/6754\/revisions"}],"predecessor-version":[{"id":6757,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/6754\/revisions\/6757"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=6754"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=6754"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=6754"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}