1️⃣ Git Config
git config is used to configure Git settings at different levels: global, local, and system.
🔹 Setting User Information
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"These commands set your username and email globally for all repositories.
🔹 Checking Current Configuration
git config --listThis command displays all current configurations.
🔹 Setting Default Text Editor
git config --global core.editor "code --wait" # VS Code
git config --global core.editor "nano" # Nano Editor🔹 Removing Configurations
git config --global --unset user.name
git config --global --unset user.email2️⃣ Git Reflog
git reflog is used to track the history of all references in a repository, even those that are not part of git log.
🔹 Viewing the Reflog History
git reflogThis command shows all actions related to HEAD, including commits, resets, and checkouts.
🔹 Recovering a Lost Commit
If you accidentally reset or deleted a commit, use the commit hash from git reflog to restore it:
git checkout🔹 Clearing the Reflog
git reflog expire --expire=now --all
git gc --prune=nowThis removes all reflog entries.
3️⃣ Git Tag
git tag is used to mark specific commits with a label, commonly for versioning.
🔹 Creating a Lightweight Tag
git tag v1.0.0This tags the latest commit as v1.0.0.
🔹 Creating an Annotated Tag (with message)
git tag -a v1.0.0 -m "Version 1.0.0 release"🔹 Listing All Tags
git tag🔹 Deleting a Tag
git tag -d v1.0.0🔹 Pushing Tags to Remote Repository
git push origin v1.0.0 # Push a specific tag
git push origin --tags # Push all tags🔹 Checking Out a Tag
git checkout tags/v1.0.0🔹 Creating a Branch from a Tag
git checkout -b new-branch v1.0.0📌 Summary
| Command | Description |
|---|---|
git config --global user.name "Your Name" |
Set global username |
git config --global user.email "your.email@example.com" |
Set global email |
git config --list |
Show all configurations |
git reflog |
Show reference logs (history of HEAD movements) |
git reflog expire --expire=now --all |
Clear reflog history |
git tag v1.0.0 |
Create a lightweight tag |
git tag -a v1.0.0 -m "Version 1.0.0 release" |
Create an annotated tag |
git push origin --tags |
Push all tags to remote |