Sitemap

GIT: COMPLETE BEGINNER GUIDE

4 min readJun 8, 2026

--

INTRODUCTION TO GIT

Git is a distributed Version Control System (VCS) created by Linus Torvalds in 2005. It helps developers track changes in source code, collaborate with teams, maintain project history, and manage different versions of a project.

Why Git?

  • Tracks code changes
    - Supports collaboration
    - Maintains project history
    - Enables branching and merging
    - Allows easy rollback to previous versions
    - Works offline

WHAT IS VERSION CONTROL?

Version Control is a system that records changes to files over time so you can recall specific versions later.

Without Git:
- Files become: project_final, project_final_v2, project_final_latest

With Git:
- Every change is tracked automatically.

Git VS GitHub

Press enter or click to view image in full size
Git vs GitHub

Git:
- Version control tool installed locally.

GitHub:
- Cloud platform for hosting Git repositories.

Other Platforms:
- GitLab
- Bitbucket

INSTALLING GIT

In Linux

sudo apt install git

In Mac

brew install git

In Window

Go to https://git-scm.com/install/windows website choose version and install

Check Installation

git -v

Configure User

git config — global user.name “Your Name”
git config — global user.email “your@email.com”

Check Configuration:

git config -l

CREATING A REPOSITORY

git init

Creates

.git/

This hidden folder stores all Git information.

GIT WORKFLOW

Working Directory
↓
Staging Area
↓
Local Repository
↓
Remote Repository

1. Working Directory

The Working Directory is the area where you create, edit, and delete files. Any changes made to files first exist in the Working Directory.

Example:

touch file-name

The file remains in the Working Directory until it is added to the Staging Area using the git add command.

2. Staging Area (Index)

The Staging Area acts as a temporary storage area where changes are prepared before creating a commit.

Files move to the Staging Area after executing:

git add file-name
git add .

This allows developers to review and select which changes should be included in the next commit.

3. Local Repository

The Local Repository exists on your computer.

Files are stored in the Local Repository after:

git commit -m “commit-message”

Changes are available only on your machine until they are pushed to a remote repository.

4.Remote Repository

A Remote Repository is hosted on a server such as GitHub, GitLab, or Bitbucket.

Files move from the Local Repository to the Remote Repository after:

git push orgin main

This makes the changes available to other developers and serves as a backup of the project.

Basic Commands.

git add

git commit

stage one file :

git add file-name

stage all files

git add .

view status

git status

commit changes

git comit -m “commit-message”

view commit history

git log

view changes

git diff

adding a remote repository

git remote add origin “link-of-repo”

push changes into repository

git push origin main

cloning a repository

git clone “repo-link”

check latest changes in remote repository

git fetch “repo-link”

Download latest changes

git pull “repo-link”

Reset commands

Get Jammu Ramu’s stories in your inbox

Join Medium for free to get updates from this writer.

Soft Reset:

git reset — soft HEAD~1

Removes commit but keeps changes staged.

Mixed Reset:

git reset HEAD~1

Removes commit and unstages changes.

Hard Reset:

git reset — hard HEAD~1

Removes commit and changes permanently.

Revert command

Undo Safely:

git revert commit-id

Creates a new commit that reverses changes.

Save work temporarily(STASH)

git stash

View stash

git stash list

Restore

git stash pop

Branches

A branch in Git is a lightweight, pointer to a specific commit that allows you to isolate your work from the main codebase. It lets you safely build features, fix bugs, or experiment without changing the stable “production” code.

Creating a new branch

git branch branh-name

View the all branches

git branch

Switch branch

git checkout branch-name

Creating and Switch to a branch

git checkout -b branch-name

Merging Branches

A merge is the process of combining the history and code changes from one Git branch back into another.

git merge branch-name

For merge a branch we go to the branch in which we have to merge know as target branch ,
Example feature branch merger to main branch

git checkout main
git merge feature

Merge Conflicts

Occurs when Git cannot determine which changes to keep.

Resolve:
1. Open conflicting file
2. Edit manually
3. git add .
4. git commit

GITIGNORE

The .gitignore file is used to specify files and folders that Git should ignore. Any files listed in .gitignore will not be tracked by Git and will not be pushed to the remote repository.

Example:

node_modules/
.env

REBASE

Rebase is used to move or replay commits from one branch onto another branch. It helps keep the Git history clean and linear.

Reapply Commits:

git rebase main

Interactive Rebase:

git rebase -i HEAD~5

Used to clean commit history.

Benefits:

- Code review
- Team collaboration
- Quality assurance

MOST IMPORTANT GIT COMMANDS

git init
git clone
git status
git add
git commit
git log
git diff
git branch
git switch
git checkout
git merge
git pull
git push
git fetch
git reset
git revert
git stash
git rebase

Git Best Practices

  • Commit frequently
    - Write meaningful commit messages
    - Use feature branches
    - Pull before pushing
    - Keep commits small
    - Avoid force pushing on shared branches
    - Use .gitignore properly
    - Review code before merging

CONCLUSION

Git is one of the most important tools for software developers. It enables version control, collaboration, branching, merging, and deployment workflows. Mastering Git helps developers work efficiently, recover from mistakes, and collaborate effectively on projects of any size.

--

--