by Aishik Nath


<aside> 💬 Note: This is an introductory article on git. If you are new to this technology or have heard of it for the first time, this article is for you.

</aside>

Git is a version control tool developed by Linus Torvalds (the creator of the Linux kernel) in 2005. Git stores a snapshot of the whole codebase each time you git push your code to an online repository. Repositories are locations where data is stored. In the context of Git, a repository (or repo) is like a cloud storage where your code resides. Since git saves snapshots of the codebase, there is very little chance of the whole codebase getting erased from the world in case the servers get destroyed. This article is dedicated to the basics of Git, how to set up your first repo, pull it into your computer, and push the updated code back to the online repo. If this article feels very long, scroll down below to read the TLDR.

Linus Torvalds - creator of git and the Linux kernel. He was awarded the Internet Hall of Fame in 2012. He even has an asteroid named after him, the 9793 Torvalds.

Linus Torvalds - creator of git and the Linux kernel. He was awarded the Internet Hall of Fame in 2012. He even has an asteroid named after him, the 9793 Torvalds.

Why learn git?

Git has now become the industry standard of collaboration for developers. Good knowledge of git not only allows you to collaborate better but also enables you and your organization to maintain the source code in a more manageable way. This section is continued at the end of the article.

Installing git

Installing git is simple and the documentation provided on the git website is well understandable for anyone interested in learning programming. You can download it from here.

Creating your own GitHub Repository

<aside> 📎 In this article, I will use GitHub as the repository provider. You can also use other git providers since the basic commands come from git and not any of the providers.

</aside>

GitHub is a developer platform that provides repositories for storing and collaborating on open-source projects, though you can also create private repos. To create your repository, go to github.com and sign up for an account (in case you don’t have one). After you are logged into GitHub, you will be greeted by the GitHub dashboard. To create a new repository:

  1. Use any of the available options present on the dashboard or visit github.com/new to create a new repo.
  2. Give your repo an adorable name, and choose if you’d want to create a public or private repo (public recommended for a todo provided later), choose a license (you will not need a license as of now) and click on the Create repository button. You can also add a README and a .gitignore but we would add these later ourselves.

Untitled

  1. Once your repo is created (without a README, LICENSE, or .gitignore), you shall be greeted with a page like the one below. Copy the HTTP link for cloning the repo into your machine. If you had opted for a any of those file mentioned above, you can get the HTTP link under the Code button.

Untitled

  1. Now head over to the directory (folder) where you’d like to download this repo. Now open the terminal at this location and run the following commands:
    1. git clone <https://github.com/USERNAME/REPOSITORY-NAME.git>. You can paste the HTTP link that you copied in place of the link into the above command. If this is your first time using git on the terminal, you will be prompted to log in.
    2. Once the cloning has been completed, you should see the repo present in the folder. You can also run ls to see this in the terminal. Go into the git repo using cd REPOSITORY_NAME.
PS D:\\demo> git clone <https://github.com/nathaishik/never-gonna-give-you-up.git>
Cloning into 'never-gonna-give-you-up'...
warning: You appear to have cloned an empty repository.
PS D:\\demo> ls

    Directory: D:\\demo

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----         16-Mar-24  10:59 PM                never-gonna-give-you-up

PS D:\\demo> cd .\\never-gonna-give-you-up\\
PS D:\\demo\\never-gonna-give-you-up>

Adding files to your repo from your computer