{"id":23,"date":"2021-10-14T18:46:54","date_gmt":"2021-10-14T18:46:54","guid":{"rendered":"https:\/\/blogs.oregonstate.edu\/joshkaiserdev\/?p=23"},"modified":"2021-10-21T14:44:37","modified_gmt":"2021-10-21T14:44:37","slug":"useful-git-commands","status":"publish","type":"post","link":"https:\/\/blogs.oregonstate.edu\/joshkaiserdev\/2021\/10\/14\/useful-git-commands\/","title":{"rendered":"Useful Git Commands"},"content":{"rendered":"\n<p>This week I came across a few instances where I needed to perform some action with Git or GitHub and needed to google a solution. I have used Git and GitHub many times before but it&#8217;s easy to forget the commands to use for every action. I am sure others come across similar issues, so I will chronicle some of my problems and solutions here.<\/p>\n\n\n\n<p>Problem 1: I need to create a new branch and switch to it. I have done this many times before but often forget the fastest way to do it.<\/p>\n\n\n\n<p>Solution 1: <\/p>\n\n\n\n<p>The slow way: git branch &lt;branch-name&gt; &amp;&amp; git checkout &lt;branch-name&gt;<\/p>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<p>The fast way: git checkout -b &lt;branch-name&gt;<\/p>\n<\/div><\/div>\n\n\n\n<p>Problem 2: I made some changes and committed some files to a branch. Some of the committed files pertained to the feature that branch was dedicated to developing, but others were core files I needed to modify to tinker with the feature, but shouldn&#8217;t be pulled into the more production-ready branch. To fix this I decided to revert the files back to their condition on the production-ready branch.<\/p>\n\n\n\n<p>Solution: git checkout origin\/&lt;production-ready-branch&gt; &lt;filename&gt;<\/p>\n\n\n\n<p>Problem 3: I needed to create a pull request. I had been working with Git on the command line and couldn&#8217;t remember how to make a pull request.<\/p>\n\n\n\n<p>Solution: Pull requests are made on GitHub, not the command line. Viewing the repository on GitHub got to &#8220;Pull requests&#8221;&gt;&#8221;New Pull Request&#8221; and choose the branch you want to want to merge into and the feature branch. Then click : &#8220;Create pull request&#8221;.<\/p>\n\n\n\n<p>Problem 4: Get a remote branch and checkout to it.<\/p>\n\n\n\n<p>Solution: git switch &lt;branch-name&gt;<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This week I came across a few instances where I needed to perform some action with Git or GitHub and needed to google a solution. I have used Git and GitHub many times before but it&#8217;s easy to forget the commands to use for every action. I am sure others come across similar issues, so&hellip; <a class=\"more-link\" href=\"https:\/\/blogs.oregonstate.edu\/joshkaiserdev\/2021\/10\/14\/useful-git-commands\/\">Continue reading <span class=\"screen-reader-text\">Useful Git Commands<\/span><\/a><\/p>\n","protected":false},"author":11627,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-23","post","type-post","status-publish","format-standard","hentry","category-uncategorized","entry"],"_links":{"self":[{"href":"https:\/\/blogs.oregonstate.edu\/joshkaiserdev\/wp-json\/wp\/v2\/posts\/23","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.oregonstate.edu\/joshkaiserdev\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.oregonstate.edu\/joshkaiserdev\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/joshkaiserdev\/wp-json\/wp\/v2\/users\/11627"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/joshkaiserdev\/wp-json\/wp\/v2\/comments?post=23"}],"version-history":[{"count":2,"href":"https:\/\/blogs.oregonstate.edu\/joshkaiserdev\/wp-json\/wp\/v2\/posts\/23\/revisions"}],"predecessor-version":[{"id":26,"href":"https:\/\/blogs.oregonstate.edu\/joshkaiserdev\/wp-json\/wp\/v2\/posts\/23\/revisions\/26"}],"wp:attachment":[{"href":"https:\/\/blogs.oregonstate.edu\/joshkaiserdev\/wp-json\/wp\/v2\/media?parent=23"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/joshkaiserdev\/wp-json\/wp\/v2\/categories?post=23"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/joshkaiserdev\/wp-json\/wp\/v2\/tags?post=23"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}