Git Tutorials

Welcome

Namaste and Welcome to to Git! Let’s learn Git the easy way with clear steps and real examples.

Git and GitHub

Git is a free software you install on your computer (Windows, macOS, or Linux) to track changes in your files.

GitHub is like Google Drive for Git projects. You can upload your code online, share it with others, and work together as a team. GitHub is the most popular option, but there are other similar platforms too, like GitLab, Bitbucket, and SourceForge.

Why use Git?

Git is like a smart notebook that saves every draft of your work. Imagine writing a book—Git lets you save each version so you can go back if you make a mistake. When working in a team, everyone writes their part on separate copies (branches) and later combines them into one final version (merge). In this tutorial, we’ll learn these ideas step by step in a simple way.

Version Control System

Version control systems are like a “time machine” for your code. They let you save different versions of your work, go back if you make a mistake, and work together with others. Think of it like checkpoints in a video game—you can always return to an earlier point if something goes wrong.

Before Git, developers used older systems like SCCS, CVS, SVN, and Perforce. But SCCS was expensive and hard to use. Git was later created to make version control free, easy, and accessible for everyone, which is why it’s so popular today.

Setup Git and GitHub

Git installation: You can either use the command line or download it from the official website. Git works on Windows, macOS, and Linux. Download Git here

Creating an account on GitHub is another important step. GitHub offers free accounts for everyone.

To push (upload) code to GitHub: You need to set up SSH keys. This provides a secure way to log in without entering your password every time. Since GitHub no longer allows password login, SSH key setup is required.

Terminology

Repository(Repo): A folder that Git is tracking. Like a project folder on your computer where all versions are saved.

Commit: A saved snapshot of your work. Like pressing “Save” in a video game or saving a draft of your essay.

Branch: An alternative timeline of your project. Like writing a “what-if” version of a story without changing the main one.

Merge: Combining changes from different branches into one. Like friends writing different chapters of a book and then putting them together.

Clone: Copying a repository from GitHub to your computer. Like downloading a Google Drive folder to your laptop.

Push: Sending your changes from your computer to GitHub. Like uploading files from your PC to Google Drive.

Pull: Getting the latest changes from GitHub to your computer. Like downloading the latest version of a shared Google Doc.

Stash:

Getting Started

Check your git version
To check your Git version, run this command in your terminal or command prompt:
git --version
Config Settings
Git lets you set up basic information like your username and email, which are saved in a config file. These details are added to every commit you make so others know who made the changes. You can set global settings that apply to all projects or repository-specific settings for just one project. It’s best to use the same username and email as your GitHub account when configuring Git.

Let’s set up your email and username in Git’s config file. It’s recommended to create a GitHub account first and then use the same email and username from your account. This way your commits will be properly linked to your GitHub profile.
To set your email, use this command (replace it with the email you use to log in to GitHub):
git config --global user.email "your-email@example.com"
Set your username with this command (replace it with your GitHub username):
git config --global user.name "username"
Now you can check your config settings by running this command in your terminal or command prompt:
git config --list
Repository
A repository (repo) is like a special folder on your computer that not only stores your files and folders but also keeps track of every change you make. Imagine working on a school project—your folder holds all chapters, images, and notes, but with Git as a repository, it also remembers every version, like a diary of changes. You can think of it as a CCTV camera for your folder, recording who changed what and when.

To see the current state of your repository at any time, you can run the command:
git status

We’ll cover useful Git commands here in the next section 🚀