{"id":5365,"date":"2023-07-26T22:04:45","date_gmt":"2023-07-27T03:04:45","guid":{"rendered":"https:\/\/www.incredigeek.com\/home\/?p=5365"},"modified":"2023-07-29T12:36:27","modified_gmt":"2023-07-29T17:36:27","slug":"git-cheat-sheet","status":"publish","type":"post","link":"https:\/\/www.incredigeek.com\/home\/git-cheat-sheet\/","title":{"rendered":"17 Must Know Git Commands"},"content":{"rendered":"\n<p>Quick and dirty cheat sheet for using git<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"config-user\">Configure user<\/h2>\n\n\n\n<p><code>git config --global user.name \"Username\"<\/code><\/p>\n\n\n\n<p><code>git config --global user.email \"email@email.com\"<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"initialize-git\">Initialize git<\/h2>\n\n\n\n<p><code>git init<\/code><\/p>\n\n\n\n<p>Check log of commits<\/p>\n\n\n\n<p><code>git log<\/code><\/p>\n\n\n\n<p>Check status<\/p>\n\n\n\n<p><code>git status<\/code><\/p>\n\n\n\n<p>Add all files to staging to be committed<\/p>\n\n\n\n<p><code>git add -A<\/code><\/p>\n\n\n\n<p>Setup .gitignore, to ignore files and directories<\/p>\n\n\n\n<p>Example to add .DS_Store files to the ignore file.<\/p>\n\n\n\n<p><code>echo \".DS_Store\" &gt;&gt; .gitignore<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"undo-commits\">Undo commits<\/h2>\n\n\n\n<p><code>git reset --hard<\/code><\/p>\n\n\n\n<p><a href=\"https:\/\/stackoverflow.com\/questions\/927358\/how-do-i-undo-the-most-recent-local-commits-in-git\">https:\/\/stackoverflow.com\/questions\/927358\/how-do-i-undo-the-most-recent-local-commits-in-git<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"branches\">Branches<\/h2>\n\n\n\n<p>Setup a branch<\/p>\n\n\n\n<p><code>git branch branch_name<\/code><\/p>\n\n\n\n<p>Switch to a branch<\/p>\n\n\n\n<p><code>git checkout branch_name<\/code><\/p>\n\n\n\n<p>Merge branch to master<\/p>\n\n\n\n<p><code>git checkout master<\/code><br><code>git merge branch_name<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"remote-repository-github\">Remote Repository (GitHub)<\/h2>\n\n\n\n<p><a href=\"https:\/\/docs.github.com\/en\/get-started\/getting-started-with-git\/managing-remote-repositories\">https:\/\/docs.github.com\/en\/get-started\/getting-started-with-git\/managing-remote-repositories<\/a><\/p>\n\n\n\n<p>You&#8217;ll can setup SSH keys to connect to GitHub.<\/p>\n\n\n\n<p><a href=\"https:\/\/docs.github.com\/en\/authentication\/connecting-to-github-with-ssh\/adding-a-new-ssh-key-to-your-github-account\">https:\/\/docs.github.com\/en\/authentication\/connecting-to-github-with-ssh\/adding-a-new-ssh-key-to-your-github-account<\/a><\/p>\n\n\n\n<p><code>git remote add origin git@github.com:OWNER\/REPO.git<\/code><\/p>\n\n\n\n<p>Setup origin<\/p>\n\n\n\n<p><code>git push --set-upstream origin master<\/code><\/p>\n\n\n\n<p>Upload files to GitHub<\/p>\n\n\n\n<p><code>git push origin master<\/code><\/p>\n\n\n\n<p>Verify remote origin<\/p>\n\n\n\n<p><code>git remote -v<\/code><\/p>\n\n\n\n<p>Set origin URL (Helpful if it has already been added)<\/p>\n\n\n\n<p><code>git remote set-url origin git@github.com:OWNER\/REPO.git<\/code><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Quick and dirty cheat sheet for using git Configure user git config &#8211;global user.name &#8220;Username&#8221; git config &#8211;global user.email &#8220;email@email.com&#8221; Initialize git git init Check log of commits git log Check status git status Add all files to staging to &hellip; <a href=\"https:\/\/www.incredigeek.com\/home\/git-cheat-sheet\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[792],"tags":[1539,927,1542,1540,1541,606],"class_list":["post-5365","post","type-post","status-publish","format-standard","hentry","category-programming","tag-branch","tag-git","tag-github","tag-master","tag-origin","tag-programming"],"_links":{"self":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/5365","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/comments?post=5365"}],"version-history":[{"count":6,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/5365\/revisions"}],"predecessor-version":[{"id":5380,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/5365\/revisions\/5380"}],"wp:attachment":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/media?parent=5365"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/categories?post=5365"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/tags?post=5365"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}