DEV Community

Cover image for Git & Github Cheat Sheet 2022
Ankush Singh Gandhi
Ankush Singh Gandhi

Posted on • Edited on

Git & Github Cheat Sheet 2022

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.

Setup🔽

Configuring user information used across all local repositories:

git config --global user.name "[firstname lastname]"
git config --global user.email "[valid-email]"
git config --global color.ui auto
Enter fullscreen mode Exit fullscreen mode

Setup & Init🔽

Configuring user information, initializing, and cloning repositories:

git init
git clone [url]
Enter fullscreen mode Exit fullscreen mode

Stage & Snapshot🔽

Working with snapshots and the Git staging area:

git status
git add [file]
git reset [file]
git diff
git diff --staged
git commit -m "[descriptive message]"
Enter fullscreen mode Exit fullscreen mode

Branch & Merge🔽

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

git branch
git branch [branch-name]
git checkout [branch]
git merge [branch]
git log
Enter fullscreen mode Exit fullscreen mode

Inspect & Compare🔽

Examining logs, diffs, and object information:

git log
git log branchB..branchA
git log --follow [file]
git diff branchB...branchA
git show [SHA]
Enter fullscreen mode Exit fullscreen mode

Tracking Path Changes🔽

Versioning file removes and path changes:

git rm [file]
git mv [existing-path] [new-path]
git log --stat -M
Enter fullscreen mode Exit fullscreen mode

Ignoring Patterns🔽

Preventing unintentional staging or committing of files:

Create a .gitignore file with patterns:

logs/
*.notes
pattern*/
Enter fullscreen mode Exit fullscreen mode

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

git config --global core.excludesfile [file]
Enter fullscreen mode Exit fullscreen mode

Share & Update🔽

Retrieving updates from another repository and updating local repos:

git remote add [alias] [url]
git fetch [alias]
git merge [alias]/[branch]
git push [alias] [branch]
git pull
Enter fullscreen mode Exit fullscreen mode

Rewrite History🔽

Rewriting branches, updating commits, and clearing history:

git rebase [branch]
git reset --hard [commit]
Enter fullscreen mode Exit fullscreen mode

Temporary Commits🔽

Temporarily store modified, tracked files to change branches:

git stash
git stash list
git stash pop
git stash drop
Enter fullscreen mode Exit fullscreen mode

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

❤️ SPONSER ME ON GITHUB ❤️

Image description

My other Blogs

Top comments (0)