Git Tutorial menu

Git Introduction

Git keeps a history of your project, so every change is saved and can be brought back.

The Problem Git Solves

Without version control, many people save copies like this:

Example

text
website-final.zip
website-final-2.zip
website-final-REAL.zip
website-final-REAL-ali-changes.zip

It is confusing, it wastes space, and when two people edit the same file, someone's work gets lost. Git replaces all of this with one folder and a clean history.

What is Version Control?

A version control system (VCS) records changes to files over time. With it you can:

  • See what changed, when, and who changed it
  • Go back to any earlier version
  • Work on new features without breaking the main code
  • Combine work from many people

Git is the most popular VCS. It was created in 2005 by Linus Torvalds, the creator of Linux. It is free and open source.

Git vs GitHub

GitGitHub
What it isA program on your computerA website
Works offlineYesNo
JobTracks versions of your filesStores repositories online, adds teamwork tools
Made byLinus Torvalds and the communityGitHub, owned by Microsoft
Alternatives(Git is the standard)GitLab, Bitbucket

You can use Git without GitHub, but GitHub needs Git.

Installing Git

  • Windows: download Git from the official git-scm website and install with the default options. It includes Git Bash, a terminal for Git commands.
  • macOS: run git --version in Terminal; if Git is missing, macOS offers to install it.
  • Linux: sudo apt install git on Ubuntu or Debian.

Check that it works:

Example

bash
git --version
Output
git version 2.47.0

Your version number may be different.

First-time Setup

Tell Git who you are. This name and email are saved with every commit you make:

Example

bash
git config --global user.name "Ayesha Khan"
git config --global user.email "ayesha@example.com"
git config --global init.defaultBranch main

The last line makes new projects start with a branch called main, the modern standard.

Check your settings:

Example

bash
git config --list
Output
user.name=Ayesha Khan
user.email=ayesha@example.com
init.defaultbranch=main

Use the same email you will use for GitHub. Then GitHub can link your commits to your profile.

Key Words

WordMeaning
Repository (repo)A project folder that Git tracks
CommitA saved snapshot of the project
BranchA separate line of work
RemoteA copy of the repository on another computer or on GitHub
CloneDownload a full copy of a repository

Exercise

Exercise

Which command saves your name for all Git projects on your computer?

Learn Git with a teacher

Join the Full Stack Development course at Workownix, online or in Orangi Town, Karachi, and get a certificate.

See the course Ask on WhatsApp