Getting Started with Git
Tags: browsergeneral
Published: 2020-10-09 14:00:33

---
title: Getting Started with Git
published: true
date: 2020-10-09 13:11:31 UTC
tags: browserGeneral
canonical_url: https://www.thisdot.co/blog/getting-started-with-git
---

 **Getting Started with Git** Today’s article will cover some of the basics of Git. This article is under the assumption that you have already made a GitHub repository or have access to one and basic understanding of the command line. If you haven’t, I recommend going to [https://github.com/](https://github.com/), creating an account and setting up a [repository](https://docs.github.com/en/free-pro-team@latest/github/getting-started-with-github/create-a-repo).

**The Rundown of Common Git Commands**

- **git clone** _This command is used on an existing repository and creates a copy of the target repository_
- **git status** _This command is used to show the state of your working directory and staging area_
- **git checkout** \*The command is used to switch between different branches or versions in a repository \*
- **git add** _This command is used to add changes to the staging area of your current directory_
- **git commit** _This command is used to save your changes to your local repository_
- **git push** _This command is used to upload your local repository to a remote repository_ 
- **git pull** _This command is used to download the newest updates from the remote repository_

**Cloning a Repo** Now that we’ve covered some of the basic Git commands, we’ll go through a few examples of how they get used. We’ll start with cloning or copying a remote repository for our local use. To start, you’ll navigate to your repository and find the clone button (now called Code). For this article, we’ll be using HTTPS as our cloning option.

[![git-basics-1](https://images.ctfassets.net/zojzzdop0fzx/2u9INavZ4e3ul1bITcRKql/c468fa98e72e6545003c7a7da846b81b/git-basics-1.png)](https://images.ctfassets.net/zojzzdop0fzx/2u9INavZ4e3ul1bITcRKql/c468fa98e72e6545003c7a7da846b81b/git-basics-1.png)

Now that you’ve copied that to your clipboard, we’ll be opening up the terminal and navigating to a folder that you want to clone your repository in. We’ll be using _ **git clone <insert-repo-clone-link></insert-repo-clone-link>** _ so in this case, it will be _**git clone [https://github.com/WillHutt/blog.git](https://github.com/WillHutt/blog.git)**_.

[![git-basic-2](https://images.ctfassets.net/zojzzdop0fzx/2IBJZwf6tn440g5VHsRxpA/f10ef9c6f18eb6b1a6544ee243d16d22/git-basic-2.png)](https://images.ctfassets.net/zojzzdop0fzx/2IBJZwf6tn440g5VHsRxpA/f10ef9c6f18eb6b1a6544ee243d16d22/git-basic-2.png)

**Git Status** Now, let's navigate to your new folder (it’s the name of the repo you cloned) and run a _ **git status** _ to see what’s going on.

[![git-basics-3](https://images.ctfassets.net/zojzzdop0fzx/4q6Zh7BdKdF4IdJpnrew41/c4b108a7f94d05c5ec918bf2c592497c/git-basics-3.png)](https://images.ctfassets.net/zojzzdop0fzx/4q6Zh7BdKdF4IdJpnrew41/c4b108a7f94d05c5ec918bf2c592497c/git-basics-3.png)

**Git Checkout** Looks like everything went okay. I’m now sitting in the master branch of my cloned repository. From here, we will leave the master branch and move to a new branch. The general rule of thumb is to always work in a separate branch; that way, if anything goes wrong, you’re not causing errors to the master branch. We’re now going to run _ **git checkout -b <insert-new-branch-name></insert-new-branch-name>** _.

_Huzzah! We are now on a new branch._

[![git-basics-4](https://images.ctfassets.net/zojzzdop0fzx/Io297ihoRvwFaLSSifRe1/850983faa4c98b8c65f911a04dcc8a7c/git-basics-4.png)](https://images.ctfassets.net/zojzzdop0fzx/Io297ihoRvwFaLSSifRe1/850983faa4c98b8c65f911a04dcc8a7c/git-basics-4.png)

**Git Add** Now, let's make some changes in your new branch. I’m going to edit my README file. I’ll be using _ **nano README.md** _ to edit my README file.

[![git-basics-5](https://images.ctfassets.net/zojzzdop0fzx/45JFzH6vXhYoFCLO6i1ZJR/05967ca4785f075ed150e53c6765677b/git-basics-5.png)](https://images.ctfassets.net/zojzzdop0fzx/45JFzH6vXhYoFCLO6i1ZJR/05967ca4785f075ed150e53c6765677b/git-basics-5.png)

Making some changes[![git-basics-6](https://images.ctfassets.net/zojzzdop0fzx/5JlZ3o3uagj9W9H0OKt0Kq/06e04ab26d5ec38be7483e3e17434ac9/git-basics-6.png)](https://images.ctfassets.net/zojzzdop0fzx/5JlZ3o3uagj9W9H0OKt0Kq/06e04ab26d5ec38be7483e3e17434ac9/git-basics-6.png)

Now that we’ve saved those changes, let's run a _ **git status** _ and see what has been changed.

[![git-basics-7](https://images.ctfassets.net/zojzzdop0fzx/71y6ZVAd5DXrKnEFNBl5qs/1569c1734f0eb8e19e805fa8e1a350c4/git-basics-7.png)](https://images.ctfassets.net/zojzzdop0fzx/71y6ZVAd5DXrKnEFNBl5qs/1569c1734f0eb8e19e805fa8e1a350c4/git-basics-7.png)

Sweet! It shows that we’ve made some changes. Let's add those changes to our branch. We’ll be using git add to add those to the staging area. With git add, we can either use _ **git add .** _ to add all of my changes or we can be more specific with _ **git add <insert-file-name></insert-file-name>** _.

[![git-basics-8](https://images.ctfassets.net/zojzzdop0fzx/gMKeX76SWEX4PUSpD9OGy/ac1b44fca7af47dfa306f63c8d6ca5a9/git-basics-8.png)](https://images.ctfassets.net/zojzzdop0fzx/gMKeX76SWEX4PUSpD9OGy/ac1b44fca7af47dfa306f63c8d6ca5a9/git-basics-8.png)

After that git add, I ran a _ **git status** _ and you can see that the text is now green indicating it has been added.

**Git Commit** Now we want to commit the newest changes to your branch. We’ll start by using _ **git commit** _, which brings up our handy commit message prompt.

[![git-basics-9](https://images.ctfassets.net/zojzzdop0fzx/WC3pTAyYhK8sfZU2fGHn0/0930b56d226543ba0aff8ee4ba3ce7aa/git-basics-9.png)](https://images.ctfassets.net/zojzzdop0fzx/WC3pTAyYhK8sfZU2fGHn0/0930b56d226543ba0aff8ee4ba3ce7aa/git-basics-9.png)

Here we will give a short description of what changed. We won’t go into detail about commit message standards in this article. We’ll keep it super simple and mention that we are updating our README documentation.

[![git-basics-10](https://images.ctfassets.net/zojzzdop0fzx/nRgPnHD3TaWstRHuN1SCf/6bd48b4bb2e99d74a7fe29de3e54bda5/git-basics-10.png)](https://images.ctfassets.net/zojzzdop0fzx/nRgPnHD3TaWstRHuN1SCf/6bd48b4bb2e99d74a7fe29de3e54bda5/git-basics-10.png)

Awesome! Everything went as planned and we’ve now committed our changes.[![git-basics-11](https://images.ctfassets.net/zojzzdop0fzx/Jbn84wYM6htDJyhD8b7c2/cb855a1121aacbab0844581e648bda3e/git-basics-11.png)](https://images.ctfassets.net/zojzzdop0fzx/Jbn84wYM6htDJyhD8b7c2/cb855a1121aacbab0844581e648bda3e/git-basics-11.png)

**Git Push** Finally, with all of that done, we can move on to pushing the local changes to your remote repository. We’ll do this with _ **git push origin <insert-branch-name></insert-branch-name>** _ and in this case, it will be _ **git push origin new-branch-yay** _. Here, it will ask for your username and password for GitHub, so go ahead and enter those.

[![git-basics-12](https://images.ctfassets.net/zojzzdop0fzx/6PADSKJudIJXvQv3SQgCXw/d1ec0898df38a89b8fed0f22400b6a07/git-basics-12.png)](https://images.ctfassets.net/zojzzdop0fzx/6PADSKJudIJXvQv3SQgCXw/d1ec0898df38a89b8fed0f22400b6a07/git-basics-12.png)

_Tada! We have pushed to your repository branch_[![git-basics-13](https://images.ctfassets.net/zojzzdop0fzx/11dy7HqrOgtGkMo5LvIdhW/f489beb476e7f762725b11055678ea87/git-basics-13.png)](https://images.ctfassets.net/zojzzdop0fzx/11dy7HqrOgtGkMo5LvIdhW/f489beb476e7f762725b11055678ea87/git-basics-13.png)

**Merging** We now need to make a pull request to get that change into the master branch. To do that, go back over to GitHub and head to your repository. Once there, we will select Pull requests and click on the New pull request button.

[![git-basics-14](https://images.ctfassets.net/zojzzdop0fzx/52PK7IJzUtlJGz9IMAUFRU/c2d4761bae81bd55903b2f42787a1b85/git-basics-14.png)](https://images.ctfassets.net/zojzzdop0fzx/52PK7IJzUtlJGz9IMAUFRU/c2d4761bae81bd55903b2f42787a1b85/git-basics-14.png)

Sweet! Now that we’ve done that, make sure the branch you want to merge is selected. That branch will be your compare while the place you want to merge into will be the base.

[![git-basics-15](https://images.ctfassets.net/zojzzdop0fzx/9LvCM4sA62CpjohkFiXrN/965d5afcdf6789eb84f7f7510657f883/git-basics-15.png)](https://images.ctfassets.net/zojzzdop0fzx/9LvCM4sA62CpjohkFiXrN/965d5afcdf6789eb84f7f7510657f883/git-basics-15.png)

Woot! Now that everything is selected properly, go ahd and click the Create pull request button. This will take us to your last step on creating a pull request.

[![git-basics-16](https://images.ctfassets.net/zojzzdop0fzx/27sJEvLTrVMbscUW02UQoU/2c08f85938047a1a7062d62e96ae614e/git-basics-16.png)](https://images.ctfassets.net/zojzzdop0fzx/27sJEvLTrVMbscUW02UQoU/2c08f85938047a1a7062d62e96ae614e/git-basics-16.png)

As you can see in the image above, you have a variety of options. We’re just going to focus on hitting the Create pull request button.

[![git-basics-17](https://images.ctfassets.net/zojzzdop0fzx/58U8kBFwGLDcGWATodmhme/9e2f3de75a6145cc0d741794dbf6930f/git-basics-17.png)](https://images.ctfassets.net/zojzzdop0fzx/58U8kBFwGLDcGWATodmhme/9e2f3de75a6145cc0d741794dbf6930f/git-basics-17.png)Now we have ourselves a pull request! Before we click that Merge pull request button, we’re going to select the white arrow to the right of it. This shows a few different merging options that we can choose from. For now, select Squash and merge and confirm it. This will keep things simple and clean, allowing our history of commits to be nice and orderly. That is super useful when you need to go back and see what changes were made without seeing a ton of merges associated with one pull request.

[![git-basics-18](https://images.ctfassets.net/zojzzdop0fzx/4qp8M45u7VM1va2qQleuwV/ddfab22b1b4e80c0500009032c4a2e24/git-basics-18.png)](https://images.ctfassets.net/zojzzdop0fzx/4qp8M45u7VM1va2qQleuwV/ddfab22b1b4e80c0500009032c4a2e24/git-basics-18.png)

Success! We have merged your pull request and updated master with your latest changes. Now we have one last thing left before we’re done with your now merged pull request. We need to click the Delete branch button to help keep your repository branches nice and clean.

[![git-basics-19](https://images.ctfassets.net/zojzzdop0fzx/4pYxh6aUqgWgPi8qqxVcLF/656cd4e2f8f92208a1835e40c8e0dc3c/git-basics-19.png)](https://images.ctfassets.net/zojzzdop0fzx/4pYxh6aUqgWgPi8qqxVcLF/656cd4e2f8f92208a1835e40c8e0dc3c/git-basics-19.png)

Navigate back to the homepage of the remote repository on GitHub and we can see that the master branch has been updated.

[![git-basics-20](https://images.ctfassets.net/zojzzdop0fzx/6aryD1VEKkOHgqisapOECM/37ab20af8f0482def55acb922bb2ba12/git-basics-20.png)](https://images.ctfassets.net/zojzzdop0fzx/6aryD1VEKkOHgqisapOECM/37ab20af8f0482def55acb922bb2ba12/git-basics-20.png)

**Git Pull** Now, we'll do a _ **git pull** _ to get the latest updates from our remote repository. To do that, we’ll change branches in our terminal. In my case, I’ll be moving from my new-branch-yay back to my master branch. In order to do so, we’ll use _ **git checkout master** _. Once on master, we’ll use a _ **git pull** _ to get the latest update to master.

[![git-basics-21](https://images.ctfassets.net/zojzzdop0fzx/5AIAR3L7njNrjir1okpKQm/bad26ea021a15995fcffabae21b11ea9/git-basics-21.png)](https://images.ctfassets.net/zojzzdop0fzx/5AIAR3L7njNrjir1okpKQm/bad26ea021a15995fcffabae21b11ea9/git-basics-21.png)

**Conclusion** We made it to the end! I hope this article was helpful and you were able to learn 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 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](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](https://www.thisdot.co)._