
Learning GitHub Commands is one of the most valuable skills for every developer in 2026. Whether you're building a simple portfolio website, working on enterprise software, or contributing to open-source projects, Git and GitHub help you manage code efficiently, collaborate with teams, and maintain a complete history of your project.
If you've ever searched for commands like git clone, git commit, git push, or git pull, you're in the right place. This comprehensive Git & GitHub Commands Cheat Sheet explains every essential command with practical examples, professional workflows, and best practices that beginners and experienced developers can use daily.
If you're completely new to version control, we recommend starting with our Complete Git & GitHub Mastery Guide . It explains repositories, commits, branches, and workflows before you begin using individual Git commands.
- Understand how Git works behind the scenes.
- Master the most important GitHub Commands.
- Learn the complete Git workflow used by professional developers.
- Avoid common mistakes while working with repositories.
- Use Git confidently in personal and team projects.
What is Git?
Git is a distributed version control system (DVCS) created by Linus Torvalds in 2005. It allows developers to track changes in source code, collaborate with other developers, restore previous versions, and safely experiment without losing work.
Instead of creating multiple folders like project-final, project-final-v2, or project-final-latest, Git stores every change as a commit. This creates a complete project history that can be reviewed or restored at any time.
- Track every code change.
- Collaborate without overwriting teammates' work.
- Restore previous versions instantly.
- Create feature branches safely.
- Maintain a clean development workflow.
Key Features of Git
- Distributed architecture
- Fast performance
- Offline development support
- Powerful branching system
- Complete version history
- Easy merging
- Open-source and free
What is GitHub?
GitHub is a cloud-based platform that hosts Git repositories online. While Git manages your project locally, GitHub makes collaboration easier by providing repository hosting, Pull Requests, Issues, Discussions, Actions, Releases, and code review features.
Think of Git as the engine that tracks changes, while GitHub is the platform where teams collaborate, review code, and deploy projects.
| Git | GitHub |
|---|---|
| Version Control Software | Cloud Repository Hosting Platform |
| Works Offline | Requires Internet for Synchronization |
| Tracks Changes | Stores Repositories Online |
| Handles Branches & Commits | Handles Collaboration & Pull Requests |
| Installed on Your Computer | Accessible Through Browser or Desktop App |
Why Should Every Developer Learn Git?
Modern software development relies heavily on Git. Almost every company expects developers to understand GitHub Commands before joining a project. From startups to enterprise organizations, Git has become the industry standard for version control.
- Write or modify your code.
- Track changes using Git.
- Commit your progress locally.
- Push commits to GitHub.
- Collaborate using Pull Requests.
- Review, merge, and deploy your code.
Info!
If you're preparing for software development interviews, Git is one of the most commonly expected technical skills. Many interviewers ask practical questions about commits, branches, merges, and conflict resolution.
Understanding the Git Workflow
Before learning individual GitHub Commands, it's important to understand the overall workflow. Every Git command fits into one of the following stages.
Working Directory
│
▼
git add
│
▼
Staging Area
│
▼
git commit
│
▼
Local Repository
│
▼
git push
│
▼
GitHub Repository
Prerequisites Before Learning GitHub Commands
- Basic computer knowledge
- A code editor such as Visual Studio Code
- A GitHub account
- Git installed on your computer
- Basic understanding of folders and files
In the next part, you'll learn how to install Git on Windows, macOS, and Linux, configure your identity, verify the installation, and create your first Git repository with practical examples.
Installing Git on Windows, macOS, and Linux
Before using any GitHub Commands, you need to install Git on your computer. Git is available for Windows, macOS, and Linux, and the installation process only takes a few minutes.
Info!
Always download Git from the official website to ensure you receive the latest stable version with security updates.
Install Git on Windows
- Visit the official Git website.
- Download the latest Windows installer.
- Run the installer using the recommended settings.
- Complete the installation wizard.
- Restart your terminal or Visual Studio Code.
Install Git on macOS
If you have Homebrew installed, open Terminal and run the following command.
brew install git
Alternatively, installing Xcode Command Line Tools will also install Git automatically.
Install Git on Linux (Ubuntu/Debian)
sudo apt update
sudo apt install git
Verify Git Installation
After installation, verify that Git is correctly installed.
git --version
Example output:
git version 2.49.0
Configure Git for the First Time
Before creating your first repository, configure your Git identity. Every commit stores the author's name and email address.
Set Your Username
git config --global user.name "Maxon"
Set Your Email Address
git config --global user.email "maxoncodes@example.com"
Verify Configuration
git config --list
Info!
Use the same email address that is associated with your GitHub account if you want your commits to appear correctly on your GitHub profile.
| Command | Description |
|---|---|
git config --global user.name |
Sets your Git username. |
git config --global user.email |
Sets your email address. |
git config --list |
Displays all Git configuration settings. |
Create Your First Git Repository
A repository (or repo) is the place where Git stores your project history. Every software project starts with a repository.
Create a New Project Folder
mkdir my-first-project
cd my-first-project
Initialize Git
git init
Git creates a hidden .git folder that stores commits, branches, configuration files, and the complete history of your project.
Info!
Never delete the .git directory unless you intentionally want to remove Git version control from the project.
Check Repository Status
git status
Initially, Git will report that there are no commits and no tracked files.
On branch main
No commits yet
nothing to commit
Create Your First File
Create a simple HTML file inside your project.
<!DOCTYPE html>
<html>
<head>
<title>My First Git Project</title>
</head>
<body>
<h1>Hello Git</h1>
</body>
</html>
Track New Files
Git doesn't automatically track newly created files. You need to add them to the staging area.
git add index.html
To stage every file inside the current directory, use:
git add .
git status before using git add .. This prevents accidentally committing unnecessary files.
Check the Current Status
git status
Example output:
Changes to be committed:
new file: index.html
Understanding the Three Git States
| State | Description |
|---|---|
| Working Directory | Files you're currently editing. |
| Staging Area | Files prepared for the next commit. |
| Repository | Files permanently saved in Git history. |
git add moves changes into the staging area, while git commit saves those staged changes permanently.
Now that your repository is ready and files are being tracked, it's time to create your first commit.
Create Your First Commit
Once your files are added to the staging area, the next step is creating a commit. A commit is like a snapshot of your project at a specific point in time. Every commit contains a unique ID, author information, timestamp, and a descriptive message.
Create a Commit
git commit -m "Initial project setup"
Info!
Always write meaningful commit messages. A good commit message helps you and your teammates understand what changed without opening the code.
| Good Commit Messages | Avoid |
|---|---|
| Add login authentication | Update |
| Fix navbar responsive issue | Fix |
| Create user dashboard layout | Changes |
| Optimize API response time | Done |
View Commit History
Git stores every commit permanently unless you intentionally rewrite history. You can display all previous commits using the following command.
git log
Example output:
commit 4a9e8c1d53d...
Author: Maxon
Date: Tue Jun 23
Initial project setup
Compact Commit History
git log --oneline
Info!
The --oneline option displays each commit on a single line, making it much easier to navigate large projects.
Check Repository Status
The git status command is one of the most frequently used Git commands. It tells you which files are modified, staged, or untracked.
git status
git status before almost every commit to verify exactly what will be committed.
View File Differences
Before committing changes, it's often useful to review exactly what has changed.
Compare Working Directory Changes
git diff
Compare Staged Changes
git diff --staged
Info!
Reviewing changes before committing helps prevent accidental bugs and unnecessary modifications from entering your repository.
Rename Files
Instead of manually renaming files, use Git so the file history is preserved.
git mv old-file.html new-file.html
Delete Files
To remove a file from both your project and Git tracking, use:
git rm index.html
After removing the file, create a new commit to save the change.
git commit -m "Remove unused HTML file"
git rm permanently stages the file for deletion. Double-check before committing.
Restore Modified Files
If you've modified a file but want to discard those changes before staging them, use:
git restore index.html
Warning!
This command permanently discards uncommitted changes. Make sure you no longer need those edits before running it.
Unstage Files
If you've already staged a file using git add but don't want to include it in the next commit, remove it from the staging area.
git restore --staged index.html
Git Command Cheat Sheet
| Command | Purpose |
|---|---|
git init |
Create a new Git repository. |
git status |
Check repository status. |
git add . |
Stage all files. |
git commit -m "message" |
Create a new commit. |
git log |
View commit history. |
git log --oneline |
Compact commit history. |
git diff |
View unstaged changes. |
git diff --staged |
View staged changes. |
git mv |
Rename files. |
git rm |
Delete tracked files. |
git restore |
Discard local changes. |
git restore --staged |
Remove files from staging. |
Real-World Development Workflow
Below is a simple workflow followed by most developers while working on a project.
- Create or edit project files.
- Run
git statusto review changes. - Stage required files using
git add. - Verify staged changes with
git diff --staged. - Create a meaningful commit using
git commit -m. - Review history using
git log --oneline.
At this point you've learned how to create repositories, track files, create commits, inspect history, compare changes, restore files, and maintain a clean commit history. These commands form the foundation of every professional Git workflow.
Understanding Git Branches
A Git branch is an independent line of development. Instead of making changes directly to the main project, developers create separate branches for new features, bug fixes, or experiments. This approach keeps the main branch stable while allowing multiple developers to work on different tasks simultaneously.
Typical Branch Structure
main
│
├── login-feature
│
├── payment-feature
│
├── dark-mode
│
└── bugfix-navbar
View All Branches
To display all available branches in your repository, use the following command.
git branch
Example output:
* main
Info!
The branch marked with an asterisk (*) is your currently active branch.
Create a New Branch
Create a new branch whenever you start working on a new feature or bug fix.
git branch login-feature
This command creates the branch but doesn't switch to it automatically.
Switch Between Branches
To move from one branch to another, use the git switch command.
git switch login-feature
You can also use the older command:
git checkout login-feature
git switch instead of git checkout because it is simpler and more intuitive.
Create and Switch in One Command
You can create a new branch and switch to it immediately.
git switch -c dashboard-feature
Older Git versions use:
git checkout -b dashboard-feature
Check Your Current Branch
git branch
Example output:
main
* dashboard-feature
Branch Workflow Example
- Create a new branch.
- Switch to the branch.
- Write your code.
- Stage your changes using
git add. - Create a commit.
- Merge the branch into
main. - Delete the completed branch.
Merge a Branch
Once your feature is complete, merge it into the main branch.
Step 1: Switch to Main
git switch main
Step 2: Merge the Feature Branch
git merge login-feature
Git combines the changes from login-feature into the main branch.
Delete a Branch
After successfully merging a branch, remove it to keep your repository clean.
git branch -d login-feature
Info!
The -d option safely deletes a branch only if it has already been merged.
Force delete a branch if required.
git branch -D login-feature
Warning!
Avoid using -D unless you're absolutely sure you no longer need the branch. It permanently removes unmerged work.
Understanding Merge Conflicts
A merge conflict occurs when Git cannot automatically determine which version of the code should be kept. This usually happens when two developers modify the same line of the same file.
index.html while Developer B also edits line 20. Git requires manual intervention to resolve the conflict.
Resolve a Merge Conflict
- Open the conflicted file.
- Locate the conflict markers.
- Choose the correct code.
- Remove Git conflict markers.
- Save the file.
- Run
git add. - Create a new commit.
Conflict Example
<<<<<<< HEAD
<h1>Welcome User</h1>
=======
<h1>Welcome Admin</h1>
>>>>>>> login-feature
Remove the conflict markers and keep the version you want.
Git Branch Commands Cheat Sheet
| Command | Description |
|---|---|
git branch |
View all local branches. |
git branch branch-name |
Create a new branch. |
git switch branch-name |
Switch to another branch. |
git switch -c branch-name |
Create and switch to a new branch. |
git checkout branch-name |
Switch branches (legacy command). |
git merge branch-name |
Merge a branch into the current branch. |
git branch -d branch-name |
Delete a merged branch. |
git branch -D branch-name |
Force delete a branch. |
You've now learned how professional developers use Git branches to isolate work, merge completed features, resolve conflicts, and maintain a clean repository. Mastering these commands is essential before collaborating with others on GitHub.
Working with Remote Repositories
Once your Git repository is connected to remote services, you'll frequently work with REST APIs, authentication, and webhooks. Learn more in our API Design Best Practices Guide .
So far, you've learned how to use Git locally. However, software development rarely happens on a single computer. Teams collaborate by storing repositories on platforms like GitHub. A remote repository is an online copy of your project that allows developers to share code, review changes, and collaborate efficiently.
Clone an Existing GitHub Repository
If a repository already exists on GitHub, you don't need to create it manually. Instead, clone it to your local machine.
git clone https://github.com/username/project.git
This command downloads the complete repository, including all commits, branches, and project history.
Info!
The git clone command automatically creates a project folder and configures the remote repository as origin.
Check Remote Repositories
To view all configured remote repositories, run:
git remote -v
Example output:
origin https://github.com/username/project.git (fetch)
origin https://github.com/username/project.git (push)
origin. You can rename or add multiple remotes if your workflow requires it.
Add a Remote Repository
If you created a local repository first and later created a GitHub repository, connect them using the following command.
git remote add origin https://github.com/username/project.git
Verify that the remote has been added successfully.
git remote -v
Rename a Remote Repository
git remote rename origin production
Remove a Remote Repository
git remote remove origin
Push Your Code to GitHub
After creating commits locally, upload them to GitHub using the git push command.
After pushing your code to GitHub, the next step is deploying your application. Follow our React and Next.js Deployment on AWS Free Tier tutorial to publish your project online.
git push origin main
If you're pushing a branch for the first time, use:
git push -u origin main
Info!
The -u option sets the upstream branch, allowing you to use git push and git pull without specifying the branch name in future.
Download the Latest Changes
When other developers update the repository, download the latest changes using:
git pull origin main
This command performs two operations:
- Downloads new commits from GitHub.
- Automatically merges those commits into your current branch.
Fetch Changes Without Merging
If you only want to download updates without immediately merging them, use:
git fetch origin
This is useful when you want to review incoming changes before merging them into your local branch.
git pull when you want to download and merge changes immediately. Use git fetch when you prefer to inspect changes before merging.
Complete GitHub Workflow
The following workflow represents how professional developers collaborate using Git and GitHub.
Create Repository
│
▼
Clone Repository
│
▼
Create Feature Branch
│
▼
Write Code
│
▼
git add
│
▼
git commit
│
▼
git push
│
▼
Create Pull Request
│
▼
Code Review
│
▼
Merge into Main
Most Frequently Used GitHub Commands
| Command | Purpose |
|---|---|
git clone URL |
Download a remote repository. |
git remote -v |
View configured remote repositories. |
git remote add origin URL |
Connect a local repository to GitHub. |
git push origin main |
Upload commits to GitHub. |
git push -u origin main |
Set upstream and push. |
git pull origin main |
Download and merge updates. |
git fetch origin |
Download updates without merging. |
git remote rename |
Rename a remote repository. |
git remote remove |
Remove a configured remote. |
Common Mistakes Beginners Make
- Pushing directly to the
mainbranch without testing. - Forgetting to pull the latest changes before starting work.
- Ignoring merge conflicts.
- Using vague commit messages like "Update" or "Fix".
- Creating large commits with unrelated changes.
- Not verifying changes with
git statusbefore pushing.
git pull before starting a new task. This ensures you're working with the latest version of the project and reduces the chance of merge conflicts.
With remote repositories, you can now collaborate with developers anywhere in the world. Understanding git clone, git push, git pull, and git fetch is essential for professional software development and is one of the most commonly tested topics in technical interviews.
Save Work Temporarily with Git Stash
Sometimes you're working on a feature, but suddenly need to switch to another branch to fix an urgent bug. Instead of creating an incomplete commit, you can temporarily save your changes using Git Stash.
Save Current Changes
git stash
View All Stashes
git stash list
Restore the Latest Stash
git stash apply
Restore and Remove the Latest Stash
git stash pop
Delete a Stash
git stash drop
Info!
Use git stash pop when you're sure you no longer need the saved stash. If you want to keep it for later, use git stash apply.
Working with Git Tags
Git tags are commonly used to mark important milestones in your project's history, such as software releases or stable versions.
Create a Lightweight Tag
git tag v1.0.0
Create an Annotated Tag
git tag -a v1.0.0 -m "First stable release"
View All Tags
git tag
Push Tags to GitHub
git push origin --tags
v1.0.0, v1.1.0, and v2.0.0 for software releases. It helps users and team members understand version history.
Undo Changes with Git Restore
If you've modified a file but haven't committed the changes, you can discard them using Git Restore.
git restore index.html
Warning!
This command permanently removes uncommitted changes from the specified file. Ensure you no longer need those edits before running it.
Undo the Last Commit
If you've made a commit but haven't pushed it yet, you can undo it while keeping the changes in your working directory.
git reset --soft HEAD~1
This removes the last commit but preserves your code changes, allowing you to modify and recommit them.
Discard the Last Commit Completely
git reset --hard HEAD~1
git reset --hard on shared branches or after pushing commits. It permanently deletes commit history and can cause problems for collaborators.
Git Reset vs Git Revert
| Git Reset | Git Revert |
|---|---|
| Removes commits from history. | Creates a new commit that reverses previous changes. |
| Best for local changes. | Best for shared repositories. |
| Can rewrite history. | Preserves project history. |
| Risky after pushing. | Safe after pushing. |
Safely Undo a Commit with Git Revert
If a commit has already been pushed to GitHub, use Git Revert instead of Git Reset. It safely creates a new commit that reverses the changes without rewriting history.
git revert HEAD
git revert over git reset because it keeps the commit history intact and avoids disrupting teammates.
Cherry-Pick a Specific Commit
Sometimes you need only one specific commit from another branch. Instead of merging the entire branch, use Git Cherry-pick.
git cherry-pick 7b4d21f
This copies the selected commit into your current branch without merging unrelated changes.
Rebase Your Branch
Git Rebase moves your branch on top of another branch, creating a cleaner and more linear project history.
git rebase main
Advanced Git Commands Cheat Sheet
| Command | Description |
|---|---|
git stash |
Temporarily save uncommitted changes. |
git stash pop |
Restore and remove the latest stash. |
git tag |
List all tags. |
git tag -a |
Create an annotated tag. |
git push origin --tags |
Push all tags to GitHub. |
git reset --soft HEAD~1 |
Undo the last commit but keep changes. |
git reset --hard HEAD~1 |
Remove the last commit permanently. |
git revert HEAD |
Safely undo a pushed commit. |
git cherry-pick |
Copy a specific commit. |
git rebase main |
Reapply commits on top of another branch. |
git stash, git revert, git rebase, and git cherry-pick can significantly improve your productivity and make collaboration easier in professional software development teams.
At this stage, you've covered Git installation, configuration, repositories, commits, branches, remote repositories, and advanced commands. You're now equipped with the essential Git skills used in real-world development environments.
Git Best Practices Every Developer Should Follow
Learning Git commands is only the first step. Professional developers also follow best practices that keep repositories clean, reduce merge conflicts, and improve collaboration. Adopting these habits early will save time and make your projects easier to maintain.
- Write clear and meaningful commit messages.
- Create a separate branch for every feature or bug fix.
- Pull the latest changes before starting new work.
- Review changes using
git diffbefore committing. - Push code frequently instead of keeping large local changes.
- Never commit passwords, API keys, or sensitive information.
- Use
.gitignoreto exclude unnecessary files. - Keep commits small and focused on a single task.
Common Git Mistakes Beginners Should Avoid
| Mistake | Recommended Solution |
|---|---|
Working directly on the main branch |
Create a feature branch before writing code. |
| Using vague commit messages | Describe exactly what changed. |
| Forgetting to pull before pushing | Run git pull before starting work. |
| Committing sensitive files | Use a properly configured .gitignore. |
| Creating huge commits | Commit small logical changes frequently. |
| Ignoring merge conflicts | Resolve conflicts immediately and test the project. |
Warning!
Never use git push --force on a shared branch unless your team explicitly agrees. Force pushing can overwrite teammates' work and permanently remove commits from the remote branch.
Frequently Asked Git Interview Questions
1. What is the difference between Git and GitHub?
Git is a distributed version control system used to track changes locally, while GitHub is a cloud platform that hosts Git repositories and provides collaboration features such as Pull Requests, Issues, and code reviews.
2. What is a Git Commit?
A commit is a snapshot of your project at a specific point in time. Every commit records the changes you've made along with the author, timestamp, and commit message.
3. What is Git Branching?
Branching allows developers to work on new features or bug fixes independently without affecting the main codebase.
4. What is the purpose of Git Stash?
Git Stash temporarily saves uncommitted changes, allowing you to switch branches or work on another task without losing your progress.
5. What is the difference between Git Reset and Git Revert?
Git Reset rewrites history and is typically used for local changes, whereas Git Revert creates a new commit that reverses previous changes, making it safer for shared repositories.
Frequently Asked Questions
Is Git difficult to learn for beginners?
No. Git has a learning curve, but once you understand repositories, commits, branches, and remotes, the remaining commands become much easier to learn.
How many Git commands should I memorize?
You don't need to memorize every command. Most developers use a core set of commands such as git status, git add, git commit, git push, git pull, git branch, and git merge on a daily basis.
Should beginners learn Git before GitHub?
Yes. Understanding Git fundamentals first makes GitHub much easier because GitHub builds on Git concepts such as repositories, commits, and branches.
Can Git be used without GitHub?
Absolutely. Git works entirely on your local machine. GitHub is an optional hosting platform that enables collaboration and remote backups.
Is Git free to use?
Yes. Git is an open-source version control system and is free for personal, educational, and commercial use.
Quick Git Commands Cheat Sheet
| Command | Use Case |
|---|---|
git init |
Create a repository. |
git clone |
Download a GitHub repository. |
git status |
Check repository status. |
git add . |
Stage all changes. |
git commit -m |
Create a commit. |
git branch |
View or create branches. |
git switch |
Switch branches. |
git merge |
Merge branches. |
git push |
Upload commits to GitHub. |
git pull |
Download and merge updates. |
git fetch |
Download updates without merging. |
git stash |
Temporarily save changes. |
git revert |
Safely undo a commit. |
git tag |
Create project versions. |
Final Thoughts
Git has become the industry standard for version control, and GitHub is one of the most widely used platforms for software collaboration. Whether you're building personal projects, contributing to open-source software, or working in a professional development team, mastering these GitHub Commands will improve your productivity and help you manage projects more efficiently.
Once you're comfortable with Git, the next logical step is learning containerized application deployment using our Docker and Kubernetes Tutorial .
Instead of memorizing every command, focus on understanding the Git workflow, practice regularly, and use this cheat sheet whenever you need a quick reference. As you gain experience, these commands will become second nature.
What's Next?
If you found this Git & GitHub Commands Cheat Sheet helpful, continue learning advanced development topics such as GitHub Actions, CI/CD pipelines, Docker, Kubernetes, and modern DevOps workflows to become a more efficient software developer. If you're planning to build backend applications, don't miss our Python for Web Development Guide , which covers APIs, frameworks, and practical backend development.