{"id":47,"date":"2019-09-13T14:37:41","date_gmt":"2019-09-13T11:37:41","guid":{"rendered":"http:\/\/www.etemkeskin.com\/?p=47"},"modified":"2020-11-09T21:40:46","modified_gmt":"2020-11-09T18:40:46","slug":"git-usage","status":"publish","type":"post","link":"https:\/\/www.etemkeskin.com\/index.php\/2019\/09\/13\/git-usage\/","title":{"rendered":"G\u0130T USAGE"},"content":{"rendered":"\n<p><strong>1.Why is Git needed?<\/strong><\/p>\n\n\n\n<p>When we want to make changes on the file (such as Word, excel, python or powerpoint file &#8230;) while working on a file, but want to keep the state before making changes, we save the file with different names (myfile1.doc, myfile2.doc, myfile3.doc etc&#8230;). However, this situation causes too many files to accumulate on our computer. <strong>Version Control Systems<\/strong> are used to prevent this situation.<\/p>\n\n\n\n<p>In addition, Version Control Systems allow different people to work on the same file.<\/p>\n\n\n\n<p><strong>2. What is Git?<\/strong><\/p>\n\n\n\n<p>Git is a Version Control System software. Also There are different Version Control System softwares.<\/p>\n\n\n\n<ul><li><a href=\"https:\/\/subversion.apache.org\/\">SVN<\/a> (Subversion),<\/li><li><a href=\"https:\/\/www.nongnu.org\/cvs\/#documentation\">CVS\u00a0<\/a>(Concurrent Versions System)  are  version control system softwares.<\/li><\/ul>\n\n\n\n<p><strong>3. What is GitHub?<\/strong><\/p>\n\n\n\n<p>GitHub is a <strong>web application<\/strong> or <strong>web storage service<\/strong> integrated with software such as <strong>git<\/strong>, where we can store our projects on the internet.  There are different web applications like GitHub. These are;<\/p>\n\n\n\n<ul><li> <strong>GitLab<\/strong><\/li><li><strong>Bitbucket <\/strong> <\/li><\/ul>\n\n\n\n<p><strong>4. How to install Git? <\/strong><\/p>\n\n\n\n<ul><li><strong>Windows<\/strong> users can download git from<strong> <\/strong><a href=\"https:\/\/gitforwindows.org\/\">https:\/\/gitforwindows.org\/<\/a> link.<\/li><li><strong>GNU\/Linux <\/strong>distro users can install with<strong> \u00a0apt-get install git-core\u00a0<\/strong><\/li><li><strong>MAC <\/strong>users can install from <strong> <\/strong><a href=\"https:\/\/sourceforge.net\/projects\/git-osx-installer\/\">https:\/\/sourceforge.net\/projects\/git-osx-installer\/<\/a> link.<\/li><\/ul>\n\n\n\n<p><strong>5. Git Usage<\/strong><\/p>\n\n\n\n<p>We can store our projects with all versions in two places.<strong> Local<\/strong>(our computer) , <strong>Remote<\/strong>(web storing service like github, gitlab&#8230;) or both <strong>local<\/strong> and <strong>remote<\/strong>\u2019 at same time.  Generally we store projects in both paces to avoid data loss.<\/p>\n\n\n\n<p>Two topics are very important in <strong>Git<\/strong> &#8216;s workflow. The first of these is  three&#8221;threes&#8221; managed in the local repository by git, the second is the branches;<\/p>\n\n\n\n<p><strong>5.1. Git Sections<\/strong><\/p>\n\n\n\n<p>Git lifecycle; \u00a0<strong>local repo<\/strong> is consists of three &#8220;trees&#8221; managed by git. First one is <strong>working directory <\/strong>that holds actual files. Second is <strong>\u00a0Stage(index)\u00a0<\/strong>and last is <strong>HEAD<\/strong> which point last <em>commit<\/em>. <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" width=\"501\" height=\"415\" src=\"http:\/\/www.etemkeskin.com\/wp-content\/uploads\/2019\/09\/is_akisi.png\" alt=\"\" class=\"wp-image-50\"\/><\/figure><\/div>\n\n\n\n<p class=\"has-text-align-center\"><strong>\u015eekil -1 git sections<\/strong><\/p>\n\n\n\n<p><em>In order to save the final version of the changes we made in our project to the git repo in the local, firstly, it is necessary to save it to the intermediate layer called staging area (also called index.) And then carry it from stage to git repo.<\/em><\/p>\n\n\n\n<p>You can create git repo in two ways in local. <br>A local repo can be created with.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">git init<\/pre>\n\n\n\n<p>or we can download the remote rep repo to our local with:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">git clone https:\/\/gitlab.com\/etem1\/trial.git <\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" width=\"686\" height=\"396\" src=\"http:\/\/www.etemkeskin.com\/wp-content\/uploads\/2019\/09\/is-akisi2.png\" alt=\"\" class=\"wp-image-54\"\/><\/figure><\/div>\n\n\n\n<p class=\"has-text-align-center\"><strong>\u015e<\/strong>ekil -2 git trees<\/p>\n\n\n\n<p>The final version of the project is sent to the repo created for our project in the local.<\/p>\n\n\n\n<p>To save the final version of the project to the repo created for our project in <strong>local<\/strong> as follows:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">git add .  <\/pre>\n\n\n\n<p>adds a change in the working directory to the staging area. Then<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">git commit \u2013m \u201cshort explanation of changes\u201d <\/pre>\n\n\n\n<p>saved to local repo.<\/p>\n\n\n\n<p><strong>5.2. Git Branches<\/strong><\/p>\n\n\n\n<p>More than one person can work on a project or we may want to do a code review in the project we will work on. Git manages this for us.<\/p>\n\n\n\n<p>When the Git project is started in Local, a branch called <strong>master<\/strong> is created.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">git branch  <\/pre>\n\n\n\n<p>with the command, we can check which branch we are in. we can switch to the branch we want by <\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">git checkout &lt;branch_name> <\/pre>\n\n\n\n<p>We can create lots of branches with different names (such as developer, admin panel branch ..)<\/p>\n\n\n\n<figure class=\"wp-block-gallery aligncenter columns-1 is-cropped\"><ul class=\"blocks-gallery-grid\"><li class=\"blocks-gallery-item\"><figure><img loading=\"lazy\" width=\"386\" height=\"155\" src=\"http:\/\/www.etemkeskin.com\/wp-content\/uploads\/2019\/09\/branch.png\" alt=\"\" data-id=\"56\" data-link=\"http:\/\/www.etemkeskin.com\/index.php\/2019\/09\/13\/git-kullanimi\/branch\/\" class=\"wp-image-56\"\/><\/figure><\/li><\/ul><\/figure>\n\n\n\n<p>In local, we can create a branch and switch to that branch as follows:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">git checkout -b &lt;branch_adi>  <\/pre>\n\n\n\n<p><strong>6. Git Configuration\u00a0 <\/strong><\/p>\n\n\n\n<p>For the remote repo that git will use, we can configure our accounts like github or gitlab locally as follows:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">git config --global user.name \u201ctrial\u201d\ngit config --global user.email trial@gmail.com\n<\/pre>\n\n\n\n<p><strong>7. Pull Remote Server to Local and Merge<\/strong><\/p>\n\n\n\n<p>We can pull the latest changes (commit) to our local repository as follows:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">git pull origin master  <\/pre>\n\n\n\n<p><strong>master<\/strong> is the name of the branch.<\/p>\n\n\n\n<p>We can merge branches as follows:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">git merge &lt;branch_name>  <\/pre>\n\n\n\n<p><strong>8. Git other Commands<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">gitk<\/pre>\n\n\n\n<p>With the internal git GUI (Graphical User Interface) we can print out our git commits in color. Graphically, we can also see past commits.<\/p>\n\n\n\n<p><strong>9. Create Version<\/strong><\/p>\n\n\n\n<p>If we are using git for our software projects, we can create a <strong>version<\/strong> before publishing the software.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">git tag 1.0.0 c325331a301a30e293b4851d8aa1bd6e9bd00049<\/pre>\n\n\n\n<p>c325331a301a30d293b4851d8aa1bd6e9bd00049\u00a0<\/p>\n\n\n\n<p>is the process number of our software version to be released.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">git log<\/pre>\n\n\n\n<p>We can see the transaction number of our last commit.<\/p>\n\n\n\n<h4 class=\"has-text-align-center\"><strong>Frequently Used Git Commands<\/strong><\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">git init                        \t     :    to start our project in local.\ngit add .                       \t     :    to submit all files at working directory to staging area.\ngit commit -m \"message\"                  :    save changes with message to git repo.\ngit log                         \t     :    to list all versions.\ngit branch                             :    to show current branch.\ngit status\t\t                         :    to show changes info. \ngit pull origin master\t               :    remote' ta master brancindeki projeyi locale \u00e7ekmek i\u00e7in kullan\u0131l\u0131r.\ngit push origin master\t               :    to push changes to remote server.\ngit -- checkout &lt;file_name>             :   to go back before save to git repo. \ngit reset HEAD &lt;file_name>              :    to reset changes at stage area\ngit checkout &lt;commit_ID>               :   to go to the desired version.\n\n========== to make git configuration  ==========\ngit config --global user.name \"etem\"\ngit config --global user.email etemkeskin@gmail.com\n\n======= create  branch both local and remote ========\nto create new branch locally with same name at remote server:\n1) git checkout -b &lt;branch_name>\n2) We submit changes to stage area and then commit them.\nChanges are pushed to remote..:\n3) git push -u origin &lt;branch_name>\n<\/pre>\n\n\n\n<h6 class=\"has-text-align-center\"><strong>Sources<\/strong><\/h6>\n\n\n\n<p style=\"font-size:12px\"><a href=\"http:\/\/www.etemkeskin.com\">https:\/\/www.etemkeskin.com<\/a><\/p>\n\n\n\n<p style=\"font-size:12px\"><a href=\"https:\/\/git-scm.com\">https:\/\/git-scm.com<\/a><\/p>\n\n\n\n<p style=\"font-size:12px\"><a href=\"https:\/\/www.atlassian.com\/git\/tutorials\/atlassian-git-cheatsheet\">https:\/\/www.atlassian.com\/git\/tutorials\/atlassian-git-cheatsheet<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1.Why is Git needed? When we want to make changes on the file (such as Word, excel, python or powerpoint file &#8230;) while working on a file, but want to keep the state before making changes, we save the file with different names (myfile1.doc, myfile2.doc, myfile3.doc etc&#8230;). However, this situation causes too many files to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v16.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>G\u0130T USAGE - blog website<\/title>\n<meta name=\"description\" content=\"When we want to make changes on the file (such as Word, excel, python or powerpoint file ...) while working on a file, but want to keep the state before making changes, we save the file with different names (myfile1.doc, myfile2.doc, myfile3.doc etc...). However, this situation causes too many files to accumulate on our computer. Version Control Systems are used to prevent this situation.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.etemkeskin.com\/index.php\/2019\/09\/13\/git-usage\/\" \/>\n<meta property=\"og:locale\" content=\"tr_TR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"G\u0130T USAGE - blog website\" \/>\n<meta property=\"og:description\" content=\"When we want to make changes on the file (such as Word, excel, python or powerpoint file ...) while working on a file, but want to keep the state before making changes, we save the file with different names (myfile1.doc, myfile2.doc, myfile3.doc etc...). However, this situation causes too many files to accumulate on our computer. Version Control Systems are used to prevent this situation.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.etemkeskin.com\/index.php\/2019\/09\/13\/git-usage\/\" \/>\n<meta property=\"og:site_name\" content=\"blog website\" \/>\n<meta property=\"article:published_time\" content=\"2019-09-13T11:37:41+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-11-09T18:40:46+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.etemkeskin.com\/wp-content\/uploads\/2019\/09\/is_akisi.png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Tahmini okuma s\u00fcresi\" \/>\n\t<meta name=\"twitter:data1\" content=\"5 dakika\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.etemkeskin.com\/#website\",\"url\":\"https:\/\/www.etemkeskin.com\/\",\"name\":\"blog website\",\"description\":\"Etem KESK\\u0130N\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/www.etemkeskin.com\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"tr\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.etemkeskin.com\/index.php\/2019\/09\/13\/git-usage\/#primaryimage\",\"inLanguage\":\"tr\",\"url\":\"http:\/\/www.etemkeskin.com\/wp-content\/uploads\/2019\/09\/is_akisi.png\",\"contentUrl\":\"http:\/\/www.etemkeskin.com\/wp-content\/uploads\/2019\/09\/is_akisi.png\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.etemkeskin.com\/index.php\/2019\/09\/13\/git-usage\/#webpage\",\"url\":\"https:\/\/www.etemkeskin.com\/index.php\/2019\/09\/13\/git-usage\/\",\"name\":\"G\\u0130T USAGE - blog website\",\"isPartOf\":{\"@id\":\"https:\/\/www.etemkeskin.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.etemkeskin.com\/index.php\/2019\/09\/13\/git-usage\/#primaryimage\"},\"datePublished\":\"2019-09-13T11:37:41+00:00\",\"dateModified\":\"2020-11-09T18:40:46+00:00\",\"author\":{\"@id\":\"https:\/\/www.etemkeskin.com\/#\/schema\/person\/dcbc30282861ce578b96a79ce8789629\"},\"description\":\"When we want to make changes on the file (such as Word, excel, python or powerpoint file ...) while working on a file, but want to keep the state before making changes, we save the file with different names (myfile1.doc, myfile2.doc, myfile3.doc etc...). However, this situation causes too many files to accumulate on our computer. Version Control Systems are used to prevent this situation.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.etemkeskin.com\/index.php\/2019\/09\/13\/git-usage\/#breadcrumb\"},\"inLanguage\":\"tr\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.etemkeskin.com\/index.php\/2019\/09\/13\/git-usage\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.etemkeskin.com\/index.php\/2019\/09\/13\/git-usage\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Ana sayfa\",\"item\":\"https:\/\/www.etemkeskin.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"G\\u0130T USAGE\"}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.etemkeskin.com\/#\/schema\/person\/dcbc30282861ce578b96a79ce8789629\",\"name\":\"etemkeskin\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.etemkeskin.com\/#personlogo\",\"inLanguage\":\"tr\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/6af0148b790691ed24ae245fb3dc773b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/6af0148b790691ed24ae245fb3dc773b?s=96&d=mm&r=g\",\"caption\":\"etemkeskin\"},\"url\":\"https:\/\/www.etemkeskin.com\/index.php\/author\/etemkeskinyahoo-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/www.etemkeskin.com\/index.php\/wp-json\/wp\/v2\/posts\/47"}],"collection":[{"href":"https:\/\/www.etemkeskin.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.etemkeskin.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.etemkeskin.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.etemkeskin.com\/index.php\/wp-json\/wp\/v2\/comments?post=47"}],"version-history":[{"count":77,"href":"https:\/\/www.etemkeskin.com\/index.php\/wp-json\/wp\/v2\/posts\/47\/revisions"}],"predecessor-version":[{"id":324,"href":"https:\/\/www.etemkeskin.com\/index.php\/wp-json\/wp\/v2\/posts\/47\/revisions\/324"}],"wp:attachment":[{"href":"https:\/\/www.etemkeskin.com\/index.php\/wp-json\/wp\/v2\/media?parent=47"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.etemkeskin.com\/index.php\/wp-json\/wp\/v2\/categories?post=47"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.etemkeskin.com\/index.php\/wp-json\/wp\/v2\/tags?post=47"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}