Visit Website

Git & GitHub Complete Cheat Sheet | 100+ Commands Explained (Beginner to Advanced)

Master Git and GitHub with this complete cheat sheet covering 100+ commands, branching, merging, remote repositories, workflows, and GitHub basics ...


Published on: July 2026 | By: Lovejeet Singh, CodeSardar


Hello friends! 👋

If you're learning programming or web development, you've probably heard about Git and GitHub. These tools are used by millions of developers to track code changes, collaborate with teams, and safely manage software projects.

The challenge is that Git includes 100+ useful commands, and beginners often struggle to remember when and how to use them.

That's why I created this complete Git & GitHub Cheat Sheet. Instead of searching different websites for commands, you'll find everything organized in one place—from basic Git commands to advanced branching, merging, remote repositories, GitHub workflows, tags, stashing, and troubleshooting.

Whether you're a beginner or an experienced developer, this guide will become a handy reference while working on real-world projects.


💡 My Experience

When I first started using Git, I was afraid of commands like merge, rebase, and reset because I didn't fully understand what they did. After working on multiple projects, I realized that learning Git isn't about memorizing commands—it's about understanding the workflow. Once I practiced committing, branching, and pushing code regularly, Git became one of the most valuable tools in my development workflow.


What Is Git?

Git is a distributed version control system that helps developers:

  • Track code changes

  • Restore previous versions

  • Collaborate with teams

  • Manage project history

  • Create branches

  • Merge changes safely

Git works entirely on your computer and doesn't require GitHub to function.


What Is GitHub?

GitHub is a cloud-based platform that hosts Git repositories.

With GitHub, you can:

  • Store repositories online

  • Collaborate with other developers

  • Review code

  • Manage issues

  • Create pull requests

  • Share open-source projects

  • Automate workflows with GitHub Actions

Think of Git as the version control tool and GitHub as an online service that hosts Git repositories.


Git Installation Commands

Check Git version:

git --version

Configure username:

git config --global user.name "Your Name"

Configure email:

git config --global user.email "you@example.com"

View configuration:

git config --list

Repository Commands

Initialize a repository:

git init

Clone an existing repository:

git clone <repository-url>

Check repository status:

git status

View help:

git help

File Management Commands

Stage a file:

git add filename

Stage all files:

git add .

Remove a file from staging:

git restore --staged filename

Delete a tracked file:

git rm filename

Rename a file:

git mv oldname newname

Commit Commands

Create a commit:

git commit -m "Initial commit"

Stage and commit tracked files:

git commit -am "Updated project"

Amend the last commit:

git commit --amend

History Commands

View commit history:

git log

Compact history:

git log --oneline

Graph view:

git log --graph --oneline --all

Show a commit:

git show

Branch Commands

List branches:

git branch

Create a branch:

git branch feature-login

Switch branches:

git switch feature-login

Create and switch:

git switch -c feature-login

Delete a branch:

git branch -d feature-login

Force delete:

git branch -D feature-login

Merge Commands

Merge a branch:

git merge feature-login

Abort merge:

git merge --abort

Remote Repository Commands

View remotes:

git remote -v

Add remote:

git remote add origin <repository-url>

Change remote URL:

git remote set-url origin <new-url>

Remove remote:

git remote remove origin

Push Commands

Push to GitHub:

git push origin main

Push a new branch:

git push -u origin feature-login

Push all branches:

git push --all

Pull Commands

Download updates:

git pull

Fetch without merging:

git fetch

Clone Commands

Clone repository:

git clone <url>

Clone into a folder:

git clone <url> project-name

Stash Commands

Save changes:

git stash

View stashes:

git stash list

Restore stash:

git stash pop

Delete stash:

git stash drop

Tag Commands

Create tag:

git tag v1.0

List tags:

git tag

Push tags:

git push --tags

Reset Commands

Soft reset:

git reset --soft HEAD~1

Mixed reset:

git reset HEAD~1

Hard reset:

git reset --hard HEAD~1

⚠️ Warning: git reset --hard permanently discards uncommitted changes.


Restore Commands

Restore a file:

git restore filename

Restore all changes:

git restore .

Difference Commands

View differences:

git diff

Compare commits:

git diff commit1 commit2

GitHub Workflow

A typical workflow looks like this:

  1. Create or clone a repository.

  2. Make changes.

  3. Stage changes with git add.

  4. Commit with git commit.

  5. Push to GitHub.

  6. Create a Pull Request (if collaborating).

  7. Review and merge changes.


Git Ignore

Create a .gitignore file to exclude files such as:

  • Log files

  • Build folders

  • Cache files

  • Environment files

  • Dependency folders (depending on the project)

This keeps your repository clean and avoids uploading unnecessary or sensitive files.


Image Suggestions

Include screenshots of:

  1. Git installation

  2. Git Bash terminal

  3. GitHub repository

  4. Branch creation

  5. Commit history

  6. Merge visualization

  7. Pull Request page

  8. GitHub repository dashboard


💡 My Recommendation

Practice Git commands on a small personal project before using them on important work. Understanding how commits, branches, and merges behave is far more valuable than memorizing every command.


💡 Pro Tip

Use small, meaningful commits with clear messages such as:

  • Fix login validation

  • Add dark mode

  • Update README

Well-written commit messages make it much easier to understand your project's history later.


⚠️ Note

Commands like git reset --hard, git clean -fd, and force pushes can permanently remove local changes. Make sure you understand their effects before using them, especially on shared repositories.


Quick Summary Table

CategoryCommands Covered
InstallationGit setup & configuration
Repositoryinit, clone, status
Filesadd, rm, mv, restore
Commitscommit, amend
Historylog, show, diff
Branchingbranch, switch, merge
Remoteremote, push, pull, fetch
Stashstash, pop, drop
Tagstag creation & management
Resetsoft, mixed, hard reset

Common Beginner Mistakes

Avoid these mistakes:

  • Forgetting to commit changes regularly.

  • Working directly on the main branch for every feature.

  • Pushing without reviewing your changes.

  • Using git reset --hard without understanding its consequences.

  • Uploading sensitive files because .gitignore wasn't configured.

  • Writing vague commit messages like "Update" or "Fix stuff".

  • Ignoring merge conflicts instead of resolving them carefully.


Interesting Facts

  • Git was created by Linus Torvalds, the creator of Linux, in 2005.

  • Git is a distributed version control system, meaning every clone contains the complete project history.

  • GitHub hosts millions of public and private repositories.

  • Branching in Git is lightweight, making feature development easier.

  • Most professional software teams use Git for version control and collaboration.


Conclusion

Git and GitHub are essential tools for modern software development. By understanding repositories, commits, branches, merges, remotes, and GitHub workflows, you'll be able to manage projects more confidently and collaborate effectively with others.

Keep this cheat sheet bookmarked and use it as a daily reference while practicing. The more you work with Git, the more natural these commands will become, helping you build better development habits over time.


Frequently Asked Questions (FAQs)

1. What is the difference between Git and GitHub?

Git is a version control system used to track changes locally, while GitHub is a cloud platform that hosts Git repositories and enables collaboration.

2. Is Git free?

Yes. Git is completely free and open-source.

3. Do I need GitHub to use Git?

No. Git works independently on your computer. GitHub is optional and mainly used for online collaboration and repository hosting.

4. What does git clone do?

It downloads a copy of an existing Git repository to your local computer.

5. What is a Git branch?

A branch allows you to develop features or fix bugs independently without affecting the main codebase until you're ready to merge.

6. Why should I use .gitignore?

A .gitignore file prevents unnecessary or sensitive files from being tracked and uploaded to your repository.

7. Is Git difficult for beginners?

Git has a learning curve, but understanding a small set of core commands—such as clone, status, add, commit, push, and pull—provides a strong foundation. As you gain experience, you can gradually learn advanced features like branching, merging, and rebasing.



Complete Video Guide/Tutorial


Post a Comment

Have a question or feedback? Share it below! Please avoid spam and stay respectful.
Visit Website
Visit Website