Git & Github Cheat Sheet 2022
Tags: github, git, showdev, opensource
Published: 2020-10-08 08:24:46



Certainly! Here's a revised and formatted version of your Git Cheat Sheet in Markdown:

---

# Git Cheat Sheet

Git is the free and open-source distributed version control system responsible for everything GitHub-related that happens locally on your computer. This cheat sheet features the most important and commonly used Git commands for easy reference.

## **Installation & GUIs🔽**

GitHub provides platform-specific installers for Git, offering both a command line tool and a graphical user interface (GUI) for day-to-day interaction, review, and repository synchronization.

- [GitHub for Windows](https://windows.github.com)
- [GitHub for Mac](https://mac.github.com)
- For Linux and Solaris platforms, the latest release is available on the [official Git website](http://git-scm.com).
- [Git for All Platforms](http://git-scm.com)

## **Setup🔽**

Configuring user information used across all local repositories:

```bash
git config --global user.name "[firstname lastname]"
git config --global user.email "[valid-email]"
git config --global color.ui auto
```

## **Setup & Init🔽**

Configuring user information, initializing, and cloning repositories:

```bash
git init
git clone [url]
```

## **Stage & Snapshot🔽**

Working with snapshots and the Git staging area:

```bash
git status
git add [file]
git reset [file]
git diff
git diff --staged
git commit -m "[descriptive message]"
```

## **Branch & Merge🔽**

Isolating work in branches, changing context, and integrating changes:

```bash
git branch
git branch [branch-name]
git checkout [branch]
git merge [branch]
git log
```

## **Inspect & Compare🔽**

Examining logs, diffs, and object information:

```bash
git log
git log branchB..branchA
git log --follow [file]
git diff branchB...branchA
git show [SHA]
```

## **Tracking Path Changes🔽**

Versioning file removes and path changes:

```bash
git rm [file]
git mv [existing-path] [new-path]
git log --stat -M
```

## **Ignoring Patterns🔽**

Preventing unintentional staging or committing of files:

Create a `.gitignore` file with patterns:

```plaintext
logs/
*.notes
pattern*/
```

Set a system-wide ignore pattern for all local repositories:

```bash
git config --global core.excludesfile [file]
```

## **Share & Update🔽**

Retrieving updates from another repository and updating local repos:

```bash
git remote add [alias] [url]
git fetch [alias]
git merge [alias]/[branch]
git push [alias] [branch]
git pull
```

## **Rewrite History🔽**

Rewriting branches, updating commits, and clearing history:

```bash
git rebase [branch]
git reset --hard [commit]
```

## **Temporary Commits🔽**

Temporarily store modified, tracked files to change branches:

```bash
git stash
git stash list
git stash pop
git stash drop
```

This cheat sheet covers the essential Git commands for various tasks. Keep it handy for quick reference!

# ❤️ SPONSER ME ON GITHUB ❤️
[![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a08qh0s78ncyxcuse3sz.png)](https://github.com/sponsors/AnkushSinghGandhi)


#### My other Blogs
{% link https://dev.to/ankushsinghgandhi/steps-to-master-python-1p06 %}
{% link https://dev.to/ankushsinghgandhi/markdown-cheat-sheet-1il5 %}