git for Beginners
Basics and Essential Commands

Let me introduce you to Git. First of all, it's important to know that Git and GitHub are not the same.
Git is a free, open-source, distributed version control system, while GitHub is a cloud platform that hosts Git files and source code remotely. You can learn to use Git and choose any cloud platform like Bit Bucket, Azure Repos, AWS Code Commit, and many more to host your Git files and source code. These platforms act as servers for the distributed version control system (VCS). You can also set up a server locally on your network or within your system using other platforms like Git Lab or Gitea.
What is Git?
Git is an open-source distributed version control system.
Open-source: Available to everyone without any fees or subscriptions.
Distributed: Everyone can have a copy of the source code and Git tracking history offline, without needing a server connection while working.
Version control system: Tracks the history of code changes by maintaining versions of it.
Why Use Git?
Git is used to track changes in code, enabling collaboration among team members without overwriting each other’s work. It helps maintain a single source of truth while working in teams using a server. Its popularity is due to huge community support, offline capabilities, and flexibility once mastered. It's also great for solo projects.
Git Basics and Core Terminologies
.git: A folder created by Git after initialization to track changes. Everything in this folder works towards tracking those changes.
Repository (repo): A directory containing source code files, along with the hidden .git folder.
Local: The repo located on your personal system.
Remote: The repo located on a server.
Unstaged: Files added to a Git project after initialization are in the unstaged area.
Staging Area: When files are added to be tracked by Git, they are in the staging area.
Branch: Creating copies of the source code with the current Git history in isolation to work on. Branches are stored as references in the
.git/refs/heads/folder.Commit: Taking a snapshot of the current repo and saving it for history. Commits are stored as compressed objects in the
.git/objectsfolder.HEAD: A special pointer indicating the current location of the commit. It is stored in the .git/HEAD file.
Common Git Commands
git init: Initializes a Git repository in the current directory with a hidden .git folder.git add <filename>: Stages changes (additions, modifications, deletions) in the specified file.git add .: Stages all changes in the working directory and sub-directories.
git commit -m "commit message": Takes a snapshot of the changes in the staging area with a commit ID and message, saving them into the repository.git commit -am "commit message": Takes a snapshot of all modified or deleted files and folders in the staging area, saving them into the repository, leaving untracked files.
git push <remote> <branch>: Uploads commits from the local repository to the specified remote repository.git log: Shows the commit history of the repository with commit messages, names, dates, and times.git log --oneline: Shows the commit history in one line each, with commit messages and shortened commit IDs.
git status: Shows the current state of the working directory and staging area.git diff <filename>: Shows the difference between the old state and the current states of the file.git diff <old branch name> <new branch name>: Shows the difference between the current and previous states of two branches.git diff <old commit id> <new commit id>: Shows the difference between the current and previous states of two commits.
git revert <commit id>: Reverts the changes in the specified commit and creates a new commit with it.git reset --hard <commit id>: Resets the changes in the specified commit ID and removes the commit from the Git history.git branch: Shows which branch you are currently working on.
Basic Developer Workflow Using Git

This guide should help you get started with Git and understand its basic concepts and commands.




