---
title: "Git and GitHub Cheat Sheet Every Developer Should Bookmark"  
description: "Git is a distributed version control system (VCS) that helps developers track changes in source code, collaborate with teams, and maintain a history of project"  
author: "Manish Kumar"  
published: 2026-06-15  
updated: 2026-06-15  
canonical: https://answers.mindstick.com/blog/398/git-and-github-cheat-sheet-every-developer-should-bookmark  
category: "software"  
tags: ["git", "github"]  
reading_time: 6 minutes  

---

# Git and GitHub Cheat Sheet Every Developer Should Bookmark

## What is Git?

[Git](https://education.github.com/git-cheat-sheet-education.pdf) is a distributed [version control system (VCS)](https://www.mindstick.com/articles/333367/version-control-best-practices-with-tfs) that helps developers track changes in [source code](https://www.mindstick.com/interview/300/what-is-the-source-code-for-display-the-picture-in-button-click-event), collaborate with teams, and maintain a history of project modifications.

### Key Features

- Tracks file changes
- Supports team collaboration
- Maintains project history
- Allows rollback to previous versions
- Fast and lightweight

### Created By

Git was created by **Linus Torvalds** in 2005 for Linux kernel development.

## What is GitHub?

GitHub is a cloud-based platform that hosts Git repositories online and provides [collaboration features](https://www.mindstick.com/news/2465/gmail-s-search-functionality-has-been-improved-and-now-include-collaboration-features).

### GitHub Features

- Repository hosting
- Pull Requests
- Issue Tracking
- [Project Management](https://www.mindstick.com/articles/23350/how-to-choose-a-project-management-platform-for-your-business)
- GitHub Actions (CI/CD)
- Code Reviews
- Team Collaboration

## Why Use Git and GitHub?

### Benefits of Git

- Version control
- Backup and recovery
- Branching and merging
- Distributed [architecture](https://www.mindstick.com/articles/249193/top-5-reasons-to-pursue-architecture)

### Benefits of GitHub

- Remote repository storage
- Team collaboration
- Open-source contribution
- Automated workflows

## Installing Git

### Windows

Download Git from:

[https://git-scm.com](https://git-scm.com/)

Verify [installation](https://www.mindstick.com/articles/711/php-installation-on-windows):

```plaintext
git --version
```

Expected output:

```plaintext
git version 2.x.x
```

## Linux

```plaintext
sudo apt update
sudo apt install git
```

## Mac

```plaintext
brew install git
```

## Git Configuration

Configure your identity:

```plaintext
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
```

Check configuration:

```plaintext
git config --list
```

## Creating Your First Repository

Create project folder:

```plaintext
mkdir MyProject
cd MyProject
```

Initialize Git:

```plaintext
git init
```

Output:

```plaintext
Initialized empty Git repository
```

## Understanding Git Workflow

Git operates in three areas:

```plaintext
Working Directory
       ↓
Staging Area
       ↓
Repository
```

### Workflow

- Create or modify files
- Add files to staging area
- Commit changes
- Push to GitHub

## Basic Git Commands

### Check Status

```plaintext
git status
```

### Add Single File

```plaintext
git add index.html
```

### Add All Files

```plaintext
git add .
```

### Commit Changes

```plaintext
git commit -m "Initial commit"
```

### View History

```plaintext
git log
```

Compact view:

```plaintext
git log --oneline
```

## Working with Branches

### View Branches

```plaintext
git branch
```

### Create Branch

```plaintext
git branch feature-login
```

### Switch Branch

```plaintext
git checkout feature-login
```

Modern alternative:

```plaintext
git switch feature-login
```

### Create and Switch

```plaintext
git checkout -b feature-login
```

### Merging Branches

Switch to main branch:

```plaintext
git checkout main
```

Merge feature branch:

```plaintext
git merge feature-login
```

### Resolving Merge Conflicts

Conflict example:

```plaintext
<<<<<<< HEAD
Current Code
=======
Incoming Code
>>>>>>> feature-login
```

Steps:

- Open conflicting file
- Remove conflict markers
- Keep desired code
- Save file

Commit changes

```plaintext
git add .
git commit -m "Resolved merge conflict"
```

## Working with Remote Repositories

### Add Remote

```plaintext
git remote add origin https://github.com/user/project.git
```

### Verify Remote

```plaintext
git remote -v
```

### Push Code

```plaintext
git push origin main
```

### Pull Changes

```plaintext
git pull origin main
```

### Fetch Changes

```plaintext
git fetch origin
```

## GitHub Fundamentals

### Create GitHub Repository

- Login to GitHub
- Click New Repository
- Enter repository name
- Click Create Repository

Connect local repository:

```plaintext
git remote add origin https://github.com/username/repo.git
git push -u origin main
```

### Cloning Repositories

Copy repository to local machine:

```plaintext
git clone https://github.com/user/project.git
```

Clone specific branch:

```plaintext
git clone -b develop https://github.com/user/project.git
```

## Pull Requests (PR)

A Pull Request allows developers to propose code changes.

### PR Workflow

```plaintext
Create Branch
      ↓
Commit Changes
      ↓
Push Branch
      ↓
Create Pull Request
      ↓
Code Review
      ↓
Merge
```

## Git Stash

Temporarily save uncommitted changes.

## Save Changes

```plaintext
git stash
```

## View Stashes

```plaintext
git stash list
```

## Apply Stash

```plaintext
git stash apply
```

## Remove Stash

```plaintext
git stash drop
```

## Git Tags

Tags mark important releases.

Create tag:

```plaintext
git tag v1.0
```

Push tag:

```plaintext
git push origin v1.0
```

List tags:

```plaintext
git tag
```

## Git Rebase

Rebase creates a cleaner commit history.

```plaintext
git checkout feature
git rebase main
```

Benefits:

- Cleaner history
- Easier review
- Linear commits

## Git Cherry-Pick

Apply specific commit to another branch.

```plaintext
git cherry-pick COMMIT_ID
```

Example:

```plaintext
git cherry-pick 6f3d2a4
```

## Undoing Changes

### Restore File

```plaintext
git restore file.txt
```

### Unstage File

```plaintext
git restore --staged file.txt
```

## Undo Last Commit

Keep changes:

```plaintext
git reset --soft HEAD~1
```

Remove changes:

```plaintext
git reset --hard HEAD~1
```

## Git Hooks

Git Hooks automate tasks before or after Git events.

Examples:

- Code formatting
- Running tests
- Security checks
- Deployment automation

Common hooks:

```plaintext
pre-commit
commit-msg
post-commit
pre-push
post-merge
```

## Git Best Practices

### Write Meaningful Commit Messages

Bad:

```plaintext
git commit -m "fix"
```

Good:

```plaintext
git commit -m "Fix login validation issue"
```

### Commit Frequently

Small commits are easier to review.

### Use Branches

Keep main branch stable.

### Pull Before Push

```plaintext
git pull origin main
```

### Ignore Unnecessary Files

Create .gitignore:

```plaintext
bin/
obj/
node_modules/
.env
```

## Complete Git & GitHub Cheat Sheet

### Repository

```plaintext
git init
git clone URL
git status
git log
```

### Staging

```plaintext
git add .
git add filename
git restore --staged filename
```

### Commit

```plaintext
git commit -m "message"
git commit --amend
```

### Branching

```plaintext
git branch
git branch new-branch
git checkout new-branch
git checkout -b new-branch
git switch new-branch
```

### Merge

```plaintext
git merge branch-name
```

### Remote

```plaintext
git remote add origin URL
git remote -v
git fetch
git pull
git push
```

### Stash

```plaintext
git stash
git stash list
git stash apply
git stash drop
```

### Tags

```plaintext
git tag
git tag v1.0
git push origin v1.0
```

### Undo

```plaintext
git restore file
git reset --soft HEAD~1
git reset --hard HEAD~1
```

### Advanced

```plaintext
git rebase main
git cherry-pick COMMIT_ID
git reflog
```

## Git Command Flow Diagram

```plaintext
Create File
    ↓
git add .
    ↓
git commit -m "message"
    ↓
git push origin main
    ↓
GitHub Repository
```

## Conclusion

Git and GitHub are essential tools for modern [software development](https://www.mindstick.com/services). Git helps developers manage source code efficiently, while GitHub enables collaboration, code reviews, project management, and [continuous integration](https://www.mindstick.com/blog/304990/what-is-continuous-integration-continuous-delivery-ci-cd-and-how-does-it-improve-software-quality).

By mastering the commands covered in this guide—from basic operations like add, commit, and push to advanced concepts such as rebase, cherry-pick, hooks, and pull requests—you can confidently manage projects of any size and collaborate effectively with development teams.

---

Original Source: https://answers.mindstick.com/blog/398/git-and-github-cheat-sheet-every-developer-should-bookmark

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
