Git is a free, open-source distributed version control system created by Linus Torvalds.
It helps developers:

Learn how to write computer programs

  • Track changes in their code over time
  • Revert to previous versions
  • Collaborate with teammates without overwriting each other’s work
  • Experiment safely using branches
  • Maintain a history of updates, features, and fixes

With Git, every developer has a full copy of the repository on their machine, making it fast, reliable, and able to work offline.

Learn how to use Git version control

What Git Is Used For

Git is commonly used to:

✅ 1. Save and manage project versions

Every commit records a snapshot of your project.

✅ 2. Work in branches without conflicts

Develop features independently and merge them later.

✅ 3. Collaborate on the same codebase

Multiple developers can work simultaneously without collisions.

✅ 4. Backup code on remote services

Platforms like GitHub, GitLab, Bitbucket store your code online.

✅ 5. Review and audit changes

Git logs, diffs, and blame help you track who changed what — and why.

Comprehensive List of Git Commands and Their Usage

1. Configuration Commands

CommandUsage
git config --global user.name "Name"Set your Git username
git config --global user.email "email@example.com"Set your Git email
git config --listDisplay all Git configurations
git config --global core.editor "editor"Set default text editor
git config --global color.ui autoEnable colored output

2. Getting Help

CommandUsage
git help <command>Help for a command
git <command> --helpDetailed manual
git help -aList all Git commands

3. Repository Setup

CommandUsage
git initInitialize a new local repository
git clone <url>Clone an existing repository

4. Basic Snapshotting (Staging & Committing)

CommandUsage
git add <file>Stage a file
git add .Stage all changes
git statusShow current status of the repo
git commit -m "message"Commit staged changes
git commit -am "message"Add & commit tracked files
git rm <file>Remove a file and stage the deletion
git mv <old> <new>Rename a file

5. Branching & Merging

CommandUsage
git branchList branches
git branch <name>Create a new branch
git branch -d <name>Delete a branch
git checkout <branch>Switch to a branch
git checkout -b <branch>Create and switch to a branch
git switch <branch>Modern way to switch branches
git switch -c <branch>Modern way to create + switch
git merge <branch>Merge a branch into current one
git rebase <branch>Reapply commits on top of another branch

6. Remote Repositories

CommandUsage
git remoteList remotes
git remote -vList remote URLs
git remote add origin <url>Connect local repo to remote
git remote remove <name>Remove a remote
git fetchDownload changes without merging
git pullFetch + merge changes
git pull --rebaseFetch + rebase
git pushUpload commits to remote
git push -u origin <branch>Push branch and set upstream

🔵 7. Inspecting Changes

CommandUsage
git logShow commit history
git log --onelineShort commit history
git log --graph --onelineVisual commit tree
git diffShow unstaged changes
git diff --stagedShow staged changes
git show <commit>Show specific commit details

8. Undoing Changes

CommandUsage
git restore <file>Undo unstaged changes
git restore --staged <file>Unstage a file
git reset <file>Unstage a file (older method)
git reset --hardReset working directory + history
git revert <commit>Create new commit that undoes previous one
git checkout <commit>View past version (detached HEAD)

9. Stashing Work

CommandUsage
git stashTemporarily save uncommitted changes
git stash applyReapply latest stash
git stash listShow all stashes
git stash dropDelete a stash
git stash popApply + delete stash

10. Tagging Versions

CommandUsage
git tagList tags
git tag <name>Create a lightweight tag
git tag -a <name> -m "message"Create annotated tag
git push --tagsPush tags to remote

11. Git Ignore

CommandUsage
.gitignoreFile that tells Git what to ignore
git rm -r --cached .Reapply .gitignore to tracked files

12. Collaboration / Fixing Conflicts

CommandUsage
Manual editingResolve merge conflicts
git mergetoolUse merge tool
git rebase --continueContinue after conflict fix
git rebase --abortAbort rebase

13. Advanced Tools

CommandUsage
git cherry-pick <commit>Apply specific commit onto another branch
git bisectFind bug-causing commit via binary search
git blame <file>Show who edited each line
git clean -fRemove untracked files
git fsckVerify repo integrity
git gcClean up unnecessary files

14. Git Submodules

CommandUsage
git submodule add <url>Add a submodule
git submodule updateUpdate submodules
git submodule initInitialize submodules

15. Aliases

CommandUsage
git config --global alias.st statusCreate git st alias
git config --global alias.cm "commit -m"Shortcut for commits

Recent Posts

Essential VS Code Extensions Every Developer Should Use

Visual Studio Code (VS Code) is powerful out of the box, but its real strength…

4 days ago

JavaScript Variables

1. What Is a Variable in JavaScript? A variable is a named container used to store data…

4 days ago

C++ Queue

1. What Is a Queue? A Queue is a linear data structure that follows the principle: FIFO – First…

6 days ago

Must-Know Angular Concepts

Angular is a full-featured frontend framework built by Google for creating large, maintainable, and high-performance web applications.…

1 week ago

Responsive Web Design (RWD)

What Is Responsive Web Design? Responsive Web Design (RWD) is an approach to building websites…

1 week ago

Geolocation API in JavaScript

The Geolocation API allows a web application to access a user’s geographical location (latitude, longitude, and more), with…

2 weeks ago