{"id":497,"date":"2017-07-24T14:50:49","date_gmt":"2017-07-24T18:50:49","guid":{"rendered":"https:\/\/folvera.commons.gc.cuny.edu\/?p=497"},"modified":"2021-09-16T14:58:07","modified_gmt":"2021-09-16T18:58:07","slug":"using-git-to-manage-changes-in-code-without-trashing-it","status":"publish","type":"post","link":"https:\/\/folvera.commons.gc.cuny.edu\/?p=497","title":{"rendered":"Using Git to Manage Changes in Code Without Trashing It"},"content":{"rendered":"<p><a title=\"What is version control? - Definition from WhatIs.com\" href=\"http:\/\/whatis.techtarget.com\/definition\/version-control\" target=\"_blank\" rel=\"noopener\">Version control<\/a> is a good idea in order to keep track of changes in your code &#8212; especially when working with multiple files in multiple directories.<\/p>\n<blockquote><p><em>&#8220;Git is a free and open source distributed code management and version control system that is distributed under the GNU General Public License version 2. In addition to software version control, Git is used for other applications including configuration management and content management.&#8221;<\/em><br \/>\n<a title=\"What is Git? - Definition from WhatIs.com\" href=\"http:\/\/searchitoperations.techtarget.com\/definition\/Git\" target=\"_blank\" rel=\"noopener\">http:\/\/searchitoperations.techtarget.com\/definition\/Git<\/a><\/p><\/blockquote>\n<p>One of the best used <a title=\"What is version control? - Definition from WhatIs.com\" href=\"http:\/\/whatis.techtarget.com\/definition\/version-control\" target=\"_blank\" rel=\"noopener\">version control<\/a>\u00a0systems is <a title=\"What is Git? - Definition from WhatIs.com\" href=\"http:\/\/searchitoperations.techtarget.com\/definition\/Git\" target=\"_blank\" rel=\"noopener\">Git<\/a> created by <a title=\"What is Linus Torvalds? - Definition from WhatIs.com\" href=\"http:\/\/searchenterpriselinux.techtarget.com\/definition\/Linus-Torvalds\" target=\"_blank\" rel=\"noopener noreferrer\">Linus Torvalds<\/a> who created <a title=\"What is Linux operating system? - Definition from WhatIs.com\" href=\"http:\/\/searchenterpriselinux.techtarget.com\/definition\/Linux\" target=\"_blank\" rel=\"noopener noreferrer\">Linux<\/a>.<\/p>\n<p><iframe loading=\"lazy\" width=\"768\" height=\"432\" src=\"https:\/\/www.youtube.com\/embed\/Vo9KPk-gqKk?feature=oembed\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<p>You can install <a title=\"What is Git? - Definition from WhatIs.com\" href=\"http:\/\/searchitoperations.techtarget.com\/definition\/Git\" target=\"_blank\" rel=\"noopener\">Git<\/a>\u00a0in various <a title=\"What is operating system (OS)? - Definition from WhatIs.com\" href=\"http:\/\/whatis.techtarget.com\/definition\/operating-system-OS\" target=\"_blank\" rel=\"noopener\">operating systems<\/a> including non-<a title=\"What is Unix? - Definition from WhatIs.com\" href=\"http:\/\/searchdatacenter.techtarget.com\/definition\/Unix\" target=\"_blank\" rel=\"noopener\">Unix<\/a> systems like <a title=\"What is Microsoft Windows? - Definition from WhatIs.com\" href=\"http:\/\/searchwindowsserver.techtarget.com\/definition\/Windows\" target=\"_blank\" rel=\"noopener noreferrer\">Windows<\/a> (Git Bash).<\/p>\n<p>First we have to introduce yourself to <a title=\"What is Git? - Definition from WhatIs.com\" href=\"http:\/\/searchitoperations.techtarget.com\/definition\/Git\" target=\"_blank\" rel=\"noopener\">Git<\/a>.<\/p>\n<ol>\n<li>Initialize <a title=\"What is Git? - Definition from WhatIs.com\" href=\"http:\/\/searchitoperations.techtarget.com\/definition\/Git\" target=\"_blank\" rel=\"noopener\">Git<\/a>.\n<pre>git init<\/pre>\n<\/li>\n<li>Then introduce yourself to <a title=\"What is Git? - Definition from WhatIs.com\" href=\"http:\/\/searchitoperations.techtarget.com\/definition\/Git\" target=\"_blank\" rel=\"noopener\">Git<\/a>. This is the way you can commit transactions.\n<pre>git config --global user.name \"[your_name]\"\r\ngit config --global user.email \"[your_email]\"<\/pre>\n<\/li>\n<li>You can use helpful colorization of commands in <a title=\"What is Git? - Definition from WhatIs.com\" href=\"http:\/\/searchitoperations.techtarget.com\/definition\/Git\" target=\"_blank\" rel=\"noopener\">Git<\/a>.\n<pre>git config --global color.ui auto<\/pre>\n<\/li>\n<li>Of course, we can edit our configuration file (<tt>.gitconfig<\/tt>). Note that files starting with a period (<tt>'.'<\/tt>) are hidden.\n<pre>[editor] .gitconfig<\/pre>\n<\/li>\n<li>At this point, you can tell <a title=\"What is Git? - Definition from WhatIs.com\" href=\"http:\/\/searchitoperations.techtarget.com\/definition\/Git\" target=\"_blank\" rel=\"noopener\">Git<\/a>\u00a0what files it has to watch.\n<pre>git add [directories\/files]<\/pre>\n<\/li>\n<li>Of course, if you prefer to add all the files in a sub-directory, you can add of it.\n<pre>git add .<\/pre>\n<\/li>\n<li>To make sure that <a title=\"What is Git? - Definition from WhatIs.com\" href=\"http:\/\/searchitoperations.techtarget.com\/definition\/Git\" target=\"_blank\" rel=\"noopener\">Git<\/a>\u00a0is running, you can ask for its status.\n<pre>git status<\/pre>\n<\/li>\n<\/ol>\n<p>Once <a title=\"What is Git? - Definition from WhatIs.com\" href=\"http:\/\/searchitoperations.techtarget.com\/definition\/Git\" target=\"_blank\" rel=\"noopener\">Git<\/a> is running and collecting changes, we can manipulate the changes.<\/p>\n<ol>\n<li>We can ask <a title=\"What is Git? - Definition from WhatIs.com\" href=\"http:\/\/searchitoperations.techtarget.com\/definition\/Git\" target=\"_blank\" rel=\"noopener\">Git<\/a> what changes have been done in our code.\n<pre>git diff<\/pre>\n<\/li>\n<li>We can also ask what changes have been made in each file.\n<pre>git diff --staged<\/pre>\n<\/li>\n<li>Once we accept the changes, we can <tt>COMMIT<\/tt> them.\n<pre>git commit -m \"[message\/memorandum]\"<\/pre>\n<\/li>\n<li>We can group these changes before committing creating <tt>branches<\/tt> &#8212; alternate copies of the project in order not to destroy the original code.\n<pre>git branch [branch_name]<\/pre>\n<\/li>\n<li>Once changes are approved in the branch, we can merge the changes into the new <tt>BRANCH<\/tt>.\n<pre>git merge<\/pre>\n<\/li>\n<li>We can then upload the new branch into the original.\n<pre>git push<\/pre>\n<\/li>\n<\/ol>\n<p><iframe loading=\"lazy\" width=\"768\" height=\"432\" src=\"https:\/\/www.youtube.com\/embed\/U8GBXvdmHT4?feature=oembed\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<p>For more information, get the <a title=\"GitHub Git Cheat Sheet\" href=\"https:\/\/services.github.com\/on-demand\/downloads\/github-git-cheat-sheet.pdf\" target=\"_blank\" rel=\"noopener\">GitHub Git Cheat Sheet<\/a> (<a href=\"https:\/\/folvera.commons.gc.cuny.edu\/files\/2017\/07\/github-git-cheat-sheet.pdf\">local copy<\/a>, owned by <a title=\"What is GitHub? - Definition from WhatIs.com\" href=\"http:\/\/searchitoperations.techtarget.com\/definition\/GitHub\" target=\"_blank\" rel=\"noopener\">GitHub<\/a>) or go to <a title=\"Git Tutorial - Try Git\" href=\"https:\/\/try.github.io\/\" target=\"_blank\" rel=\"noopener\">try.github.io<\/a>.<\/p>\n<p>I would like to thank Julia L\u00f3pez (<a title=\"@yukideluxe\" href=\"https:\/\/twitter.com\/yukideluxe\" target=\"_blank\" rel=\"noopener\">@yukideluxe<\/a>) from Spain and Kimberley Cook (<a title=\"@KimberleyCook91\" href=\"https:\/\/twitter.com\/KimberleyCook91\" target=\"_blank\" rel=\"noopener\">@KimberleyCook91<\/a>) from England for helping me put this quick tutorial together.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Version control is a good idea in order to keep track of changes in your code &#8212; especially when working with multiple files in multiple directories. &#8220;Git is a free and open source distributed code management and version control system that is distributed under the GNU General Public License version 2. In addition to software [&hellip;]<\/p>\n","protected":false},"author":7213,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"send_to_group_blog":0,"footnotes":""},"categories":[3,1,17],"tags":[],"class_list":["post-497","post","type-post","status-publish","format-standard","hentry","category-computer-programming","category-cuny","category-open-source"],"_links":{"self":[{"href":"https:\/\/folvera.commons.gc.cuny.edu\/index.php?rest_route=\/wp\/v2\/posts\/497","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/folvera.commons.gc.cuny.edu\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/folvera.commons.gc.cuny.edu\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/folvera.commons.gc.cuny.edu\/index.php?rest_route=\/wp\/v2\/users\/7213"}],"replies":[{"embeddable":true,"href":"https:\/\/folvera.commons.gc.cuny.edu\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=497"}],"version-history":[{"count":5,"href":"https:\/\/folvera.commons.gc.cuny.edu\/index.php?rest_route=\/wp\/v2\/posts\/497\/revisions"}],"predecessor-version":[{"id":503,"href":"https:\/\/folvera.commons.gc.cuny.edu\/index.php?rest_route=\/wp\/v2\/posts\/497\/revisions\/503"}],"wp:attachment":[{"href":"https:\/\/folvera.commons.gc.cuny.edu\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=497"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/folvera.commons.gc.cuny.edu\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=497"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/folvera.commons.gc.cuny.edu\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=497"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}