DEV Community

Moustafa
Moustafa

Posted on

Git Documentation - Config, Reflog, and Tags

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"
Enter fullscreen mode Exit fullscreen mode

These commands set your username and email globally for all repositories.

🔹 Checking Current Configuration

git config --list
Enter fullscreen mode Exit fullscreen mode

This 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
Enter fullscreen mode Exit fullscreen mode

🔹 Removing Configurations

git config --global --unset user.name
git config --global --unset user.email
Enter fullscreen mode Exit fullscreen mode

2️⃣ 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 reflog
Enter fullscreen mode Exit fullscreen mode

This 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 <commit-hash>
Enter fullscreen mode Exit fullscreen mode

🔹 Clearing the Reflog

git reflog expire --expire=now --all
git gc --prune=now
Enter fullscreen mode Exit fullscreen mode

This 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.0
Enter fullscreen mode Exit fullscreen mode

This 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"
Enter fullscreen mode Exit fullscreen mode

🔹 Listing All Tags

git tag
Enter fullscreen mode Exit fullscreen mode

🔹 Deleting a Tag

git tag -d v1.0.0
Enter fullscreen mode Exit fullscreen mode

🔹 Pushing Tags to Remote Repository

git push origin v1.0.0  # Push a specific tag
git push origin --tags  # Push all tags
Enter fullscreen mode Exit fullscreen mode

🔹 Checking Out a Tag

git checkout tags/v1.0.0
Enter fullscreen mode Exit fullscreen mode

🔹 Creating a Branch from a Tag

git checkout -b new-branch v1.0.0
Enter fullscreen mode Exit fullscreen mode

📌 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

Top comments (0)