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

Share
Published by
codeflare

Recent Posts

The Golden Ratio (φ)

1. What Is the Golden Ratio? The Golden Ratio, represented by the Greek letter φ (phi), is…

11 hours ago

CSS Combinators

In CSS, combinators define relationships between selectors. Instead of selecting elements individually, combinators allow you to target elements based…

3 days ago

Boolean Algebra

Below is a comprehensive, beginner-friendly, yet deeply detailed guide to Boolean Algebra, complete with definitions, laws,…

4 days ago

Why It’s Difficult to Debug Other People’s Code (And what Can be Done About it)

Debugging your own code is hard enough — debugging someone else’s code is a whole…

5 days ago

Bubble Sort Algorithm

Bubble Sort is one of the simplest sorting algorithms in computer science. Although it’s not…

1 week ago

Impostor Syndrome for Software Developers

In the world of software development—where new frameworks appear overnight, job titles evolve every three…

1 week ago