{"id":30798,"date":"2022-07-24T13:41:54","date_gmt":"2022-07-24T13:41:54","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=30798"},"modified":"2022-12-23T05:48:06","modified_gmt":"2022-12-23T05:48:06","slug":"git-lab-exercise-assignment-basic-local-workflow-part-1","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/git-lab-exercise-assignment-basic-local-workflow-part-1\/","title":{"rendered":"Git Lab Exercise &#038; Assignment: Basic local workflow: Part &#8211; 1"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">Related &#8211; Git basic local workflow<\/h3>\n\n\n\n<p><strong>These exercises aim to give you some practice with using the Git version control system.<\/strong><\/p>\n\n\n\n<p><strong>Each exercise comes in two parts: a main task that most, if not all, course attendees should be able to complete in the allocated time, as well as a stretch task for those who complete the main task quickly<\/strong><\/p>\n\n\n\n<p><strong>Main Task<\/strong><br>1. Create a new directory and change into it.<br>2. Use the&nbsp;<strong>init<\/strong>&nbsp;command to create a Git repository in that directory.<br>3. Observe that there is now a&nbsp;<strong>.git<\/strong>&nbsp;directory.<br>4. Create a&nbsp;<strong>README<\/strong>&nbsp;file.<br>5. Look at the output of the&nbsp;<strong>status<\/strong>&nbsp;command; the&nbsp;<strong>README<\/strong>&nbsp;you created should appear as an untracked file.<br>6. Use the&nbsp;<strong>add<\/strong>&nbsp;command to add the new file to the staging area. Again, look at the output of the&nbsp;<strong>status<\/strong>&nbsp;command.<br>7. Now use the&nbsp;<strong>commit<\/strong>&nbsp;command to commit the contents of the staging area.<br>8. Create a&nbsp;<strong>src<\/strong>&nbsp;directory and add a couple of files to it.<br>9. Use the&nbsp;<strong>add<\/strong>&nbsp;command, but name the directory, not the individual files. Use the&nbsp;<strong>status<\/strong>&nbsp;command. See how both files have been staged. Commit them.<br>10. Make a change to one of the files. Use the&nbsp;<strong>diff<\/strong>&nbsp;command to view the details of the change.<br>11. Next,&nbsp;<strong>add<\/strong>&nbsp;the changed file, and notice how it moves to the staging area in the&nbsp;<strong>status<\/strong>&nbsp;output. Also observe that the&nbsp;<strong>diff<\/strong>&nbsp;command you did before using add now gives no output. Why not? What do you have to do to see a&nbsp;<strong>diff<\/strong>&nbsp;of the things in the staging area? (Hint: review the slides if you can&#8217;t remember.)<br>12. Now without committing, make another change to the same file you changed in step 10. Look at the&nbsp;<strong>status<\/strong>&nbsp;output, and the&nbsp;<strong>diff<\/strong>&nbsp;output. Notice how you can have both staged and unstaged changes, even when you are talking about a single file. Observe the difference when you use the&nbsp;<strong>add<\/strong>&nbsp;command to stage the latest round of changes. Finally,&nbsp;<strong>commit<\/strong>&nbsp;them. You should now have started to get a feel for the staging area.<br>13. Use the&nbsp;<strong>log<\/strong>&nbsp;command in order to see all of the commits you made so far.<br>14. Use the&nbsp;<strong>show<\/strong>&nbsp;command to look at an individual commit. How many characters of the commit identifier can you get away with typing at a minimum?<br>15. Make a couple more commits, at least one of which should add an extra file.<\/p>\n\n\n\n<p><strong>Stretch Task<\/strong><br>1. Use the Git rm command to remove a file. Look at the&nbsp;<strong>status<\/strong>&nbsp;afterwards. Now commit the deletion.<br>2. Delete another file, but this time do not use Git to do it; e.g. if you are on Linux, just use the normal (non-Git)&nbsp;<strong>rm<\/strong>&nbsp;command; on Windows use&nbsp;<strong>del<\/strong>.<br>3. Look at the&nbsp;<strong>status<\/strong>. Compare it to the status output you had after using the Git built-in rm command. Is anything different? After this, commit the deletion.<br>4. Use the Git mv command to move or rename a file; for example, rename&nbsp;<strong>README<\/strong>&nbsp;to&nbsp;<strong>README.txt<\/strong>. Look at the status. Commit the change.<br>5. Now do another rename, but this time using the operating system&#8217;s command to do so. How does the status look? Will you get the right outcome if you were to commit at this point? (Answer: almost certainly not, so do not. \ud83d\ude42 Work out how to get the&nbsp;<strong>status<\/strong>&nbsp;to show that it will not lose the file, and then commit. Did Git at any point work out that you had done a rename?<br>6. Use&nbsp;<strong>git help log<\/strong>&nbsp;to find out how to get Git to display just the most recent 3 commits. Try it.<br>7. If you do not remember, look back in the slides to see what the&nbsp;<strong>&#8211;stat<\/strong>&nbsp;option did on the&nbsp;<strong>diff<\/strong>&nbsp;command. Find out if this also works with the show command. How about the&nbsp;<strong>log<\/strong>&nbsp;command?<br>8. Imagine you want to see a&nbsp;<strong>diff<\/strong>&nbsp;that summarizes all that happened between two commit identifiers. Use the diff command, specifying two commit identifiers joined by two dots (that is, something like&nbsp;<strong>abc123..def456<\/strong>). Check the output is what you expect.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Related &#8211; Git basic local workflow These exercises aim to give you some practice with using the Git version control system. Each exercise comes in two parts:&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[2],"tags":[],"class_list":["post-30798","post","type-post","status-publish","format-standard","hentry","category-uncategorised"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/30798","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=30798"}],"version-history":[{"count":1,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/30798\/revisions"}],"predecessor-version":[{"id":30799,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/30798\/revisions\/30799"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=30798"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=30798"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=30798"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}