Git Commands Cheat Sheet

Listen to this Post

Featured Image

🟨 SETUP

`git config –global user.name “[firstname lastname]”`

Set a name to be identified for credit when reviewing version history.

`git config –global user.email “[valid-email]”`

Set an email address associated with each history marker.

🟧 SETUP & INIT

`git init`

Initialize an existing directory as a Git repository.

`git clone

`</h2>

<h2 style="color: yellow;">Retrieve an entire repository from a hosted URL.</h2>

<h2 style="color: yellow;">🟦 STAGE & SNAPSHOT</h2>

<h2 style="color: yellow;">`git status`</h2>

Show modified files in the working directory staged for commit.

<h2 style="color: yellow;">`git add [bash]`</h2>

Add a file as it looks now to your next commit (stage).

<h2 style="color: yellow;">`git reset [bash]`</h2>

Unstage a file while retaining changes in the directory.

<h2 style="color: yellow;">`git diff`</h2>

<h2 style="color: yellow;">Show changes not yet staged.</h2>

<h2 style="color: yellow;">`git diff --staged`</h2>

<h2 style="color: yellow;">Show changes staged but not yet committed.</h2>

<h2 style="color: yellow;">🟩 BRANCH & MERGE</h2>

<h2 style="color: yellow;">`git branch`</h2>

<h2 style="color: yellow;">List branches (`` indicates the current branch).</h2>

<h2 style="color: yellow;">`git branch [branch-name]`</h2>

<h2 style="color: yellow;">Create a new branch at the current commit.</h2>

<h2 style="color: yellow;">`git checkout [bash]`</h2>

<h2 style="color: yellow;">Switch to another branch and check it out.</h2>

<h2 style="color: yellow;">`git merge [bash]`</h2>

Merge the specified branch’s history into the current branch.

<h2 style="color: yellow;">`git log`</h2>

<h2 style="color: yellow;">Show all commits in the current branch’s history.</h2>

<h2 style="color: yellow;"> You Should Know:</h2>

<h2 style="color: yellow;">Essential Git Commands for Developers</h2>

<h2 style="color: yellow;">1. Undoing Changes</h2>

- `git restore [bash]` – Discard changes in the working directory. 
- `git revert [commit-hash]` – Revert a specific commit while keeping history. 
- `git reset --hard HEAD` – Completely reset to the last commit (DANGEROUS).

<h2 style="color: yellow;">2. Remote Repositories</h2>

- `git remote -v` – List remote repositories. 
- `git push origin [bash]` – Push changes to a remote branch. 
- `git pull origin [bash]` – Fetch and merge changes from a remote branch.

<h2 style="color: yellow;">3. Stashing Changes</h2>

- `git stash` – Temporarily save uncommitted changes. 
- `git stash pop` – Reapply stashed changes.

<h2 style="color: yellow;">4. Advanced Logging</h2>

- `git log --oneline --graph` – Compact commit history with a graph. 
- `git log --author="name"` – Filter commits by author.

<h2 style="color: yellow;">5. Tagging Releases</h2>

- `git tag v1.0` – Create a lightweight tag. 
- `git tag -a v1.0 -m "Release version"` – Create an annotated tag.

<h2 style="color: yellow;">6. Rebasing (Alternative to Merge)</h2>

- `git rebase [bash]` – Reapply commits on top of another branch (cleaner history).

<h2 style="color: yellow;">7. Debugging with Git</h2>

- `git bisect start` – Binary search to find a bug-introducing commit. 
- `git blame [bash]` – See who last modified each line.

<h2 style="color: yellow;"> What Undercode Say</h2>

Git is a powerful tool for version control, but mastering it requires practice. Here are some additional Linux/Windows commands that complement Git workflows:

<h2 style="color: yellow;">Linux Commands for Git Users</h2>

- `grep "pattern" [bash]` – Search for text in files. 
- `find . -name ".txt"` – Locate files by name. 
- `chmod +x script.sh` – Make a script executable. 
- `ssh-keygen -t rsa -b 4096` – Generate SSH keys for Git authentication.

<h2 style="color: yellow;">Windows Git-Related Commands</h2>

- `where git` – Locate Git installation. 
- `taskkill /F /IM git.exe` – Force-stop Git processes. 
- `certmgr.msc` – Manage SSL certificates for Git HTTPS.

<h2 style="color: yellow;">Bonus: Git Aliases for Efficiency</h2>

[bash]
git config --global alias.co checkout 
git config --global alias.br branch 
git config --global alias.ci commit 
git config --global alias.st status 

Expected Output:

A well-structured Git cheat sheet with practical commands, advanced techniques, and complementary system commands for developers.

Prediction:

Git will continue evolving with AI-assisted commit messages and automated conflict resolution, making version control even more efficient.

(Relevant Advanced Git Techniques)

References:

Reported By: Ninadurann Git – Hackers Feeds
Extra Hub: Undercode MoN
Basic Verification: Pass βœ…

Join Our Cyber World:

πŸ’¬ Whatsapp | πŸ’¬ Telegram