{"id":152,"date":"2016-06-08T10:25:56","date_gmt":"2016-06-08T14:25:56","guid":{"rendered":"https:\/\/mberlove.com\/blog\/?p=152"},"modified":"2016-06-08T10:25:56","modified_gmt":"2016-06-08T14:25:56","slug":"git-common-tasks","status":"publish","type":"post","link":"https:\/\/mberlove.com\/blog\/git-common-tasks\/","title":{"rendered":"Git: Common Tasks"},"content":{"rendered":"<p><strong>As a git user I am no expert. <\/strong><\/p>\n<p><strong>I don&#8217;t know if I&#8217;ll ever be, yet I use it every day.<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>I&#8217;m not alone &#8212; many people recognize the critical role version control plays in development work, but it&#8217;s challenging to find time to take yourself from a working knowledge to even a moderate expertise.<\/p>\n<p>&nbsp;<\/p>\n<p>It&#8217;s something we can all work on. It would serve us well, since a working knowledge often has gaps, gaps which become a hassle in daily work life. Many times I&#8217;ve had to look up very straightforward tasks simply because I&#8217;d never learned to perform that task in git! And what I often find is that I am only one of many, many developers asking the same kinds of questions &#8212; and more often than not, the solution is a simple, one-line command!<\/p>\n<p>&nbsp;<\/p>\n<p>With that in mind, I&#8217;ve put together a list of simple, common tasks that perhaps don&#8217;t come up as often as the standard &#8220;clone &#8211; fetch &#8211; merge &#8211; pull &#8211; add- commit &#8211; push&#8221; commands you use everyday. Hopefully, you&#8217;ll recognize something in this list and make your life a bit easier\u00a0 (or at least save you a google search next time).<\/p>\n<h1>Check your branch<\/h1>\n<pre>git branch<\/pre>\n<p>or<\/p>\n<p>&nbsp;<\/p>\n<pre>git status<\/pre>\n<p>(the latter also gives you additional info).<\/p>\n<h1>List remote repos<\/h1>\n<pre>git remote -v<\/pre>\n<h1>Move to a previous commit (temporarily)<\/h1>\n<pre>git checkout &lt;commit&gt;<\/pre>\n<p>You can find the commit id with git log.<\/p>\n<h1>Move to a previous commit (permanently)<\/h1>\n<pre>git reset --hard &lt;commit&gt;<\/pre>\n<h1>Oops! Wrong branch &#8212; switch my uncommitted changes to a new branch.<\/h1>\n<pre>git checkout -b &lt;new-branch-name&gt;<\/pre>\n<h1>Compare the changes to a file between commits<\/h1>\n<pre>git diff HEAD~1 HEAD &lt;file&gt;<\/pre>\n<p>Replace the &#8216;1&#8217; with the number of commits back you want to compare. Leave off the filename to see all files.<\/p>\n<h1>Remove cached files (e.g. previously committed files now in .gitignore)<\/h1>\n<pre>git rm --cached<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>As a git user I am no expert. I don&#8217;t know if I&#8217;ll ever be, yet I use it every day. &nbsp; I&#8217;m not alone &#8212; many people recognize the critical role version control plays in development work, but it&#8217;s [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[147],"tags":[149,148,146,70,41,115],"class_list":["post-152","post","type-post","status-publish","format-standard","hentry","category-software-engineering","tag-common-tasks","tag-git","tag-guide","tag-programming","tag-software-development","tag-version-control"],"_links":{"self":[{"href":"https:\/\/mberlove.com\/blog\/wp-json\/wp\/v2\/posts\/152","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mberlove.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mberlove.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mberlove.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mberlove.com\/blog\/wp-json\/wp\/v2\/comments?post=152"}],"version-history":[{"count":2,"href":"https:\/\/mberlove.com\/blog\/wp-json\/wp\/v2\/posts\/152\/revisions"}],"predecessor-version":[{"id":155,"href":"https:\/\/mberlove.com\/blog\/wp-json\/wp\/v2\/posts\/152\/revisions\/155"}],"wp:attachment":[{"href":"https:\/\/mberlove.com\/blog\/wp-json\/wp\/v2\/media?parent=152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mberlove.com\/blog\/wp-json\/wp\/v2\/categories?post=152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mberlove.com\/blog\/wp-json\/wp\/v2\/tags?post=152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}