🔗Getting started with Git
Today’s article will cover some of the basics of Git. This article is written under the assumption that you have already made a GitHub repository or have access to one, and that you also have a basic understanding of the command line.
Now, we’ll move on to a brief rundown of the Git commands that will be used in this article, and then follow it up with how to use each of them.
- This command is used to show changes between commits and the working tree.
- This command is used to stash or remove the changes made to your working directory (no worries these haven’t gone up in smoke)
Git stash pop
- This command is used to retrieve your most recent stash made by popping it from your stash stack
Git stash list
- This command is used to display a list of your current stash entries.
Git stash apply
- This command is used to reapply a git stash, but also keep it in your stash
Alright, now we’re going to move on to how to do a git diff. I’m going to be going to my console, and heading over to the blog repo I used last time. From here, I’m going to open up my README file with nano and edit it. After saving, I’ll use a git status to verify that the changes are showing up. Now, we can see that the file is edited, but say we don’t know or remember what was changed. In this instance, we can use a git diff, and it’ll show us the changes that were made.
Say we decide we don’t want or need those README changes at the moment we can use a git stash. With that done, we’ll use git status, and we can see that those changes are gone. While the change do appear to be gone, we can easily retrieve it by doing git stash pop. Once again, we’ll use git status, and verify that the changes are back.
🔗Git stash list & apply
Alright, so we’re going to do a git stash again to get rid of our current changes. We’re going to edit the README with nano again. We’ll run another git status to verify the changes were made. Then, we’re going to do another git stash to get rid of those changes. Now, with a couple of changes stashed, we’re going to do a git stash list to see our list of stashed changes.
Now we want our initial changes. In order to get those, we’ll use a git stash apply 1. This will keep it in your git stash and it is useful if you want to apply the same changes in multiple branches.
We made it to the end! I hope this article was helpful, and that you were able to learn about, and be more comfortable with Git and GitHub. This article covered some of the basics of Git to try and help people starting out, or for those who might need a refresher.
This Dot Labs is a modern web consultancy focused on helping companies realize their digital transformation efforts. For expert architectural guidance, training, or consulting in React, Angular, Vue, Web Components, GraphQL, Node, Bazel, or Polymer, visit [thisdotlabs.com]((https://www.thisdotlabs.com).
This Dot Media is focused on creating an inclusive and educational web for all. We keep you up to date with advancements in the modern web through events, podcasts, and free content. To learn, visit thisdot.co.