This article was written over 18 months ago and may contain information that is out of date. Some content may still be relevant, but please refer to official documentation for the latest information.
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.
If you haven’t opened up a GitHub account, I recommend going to GitHub, creating an account, setting up a repository and following this guide before continuing on.
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.
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.
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.
Git stash
Nano changes and git status
Git stash again
Git stash list
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.
About the author
William Hutt
Software Engineer
I'm a software engineer with an interest in web development.