A Git commit is the core building block of version control. It represents a snapshot of your project at a specific point in time. Every time you make changes to your code and save them using a commit, Git records those changes along with a message that explains what was done.
A good commit message is essential for collaboration and project maintenance. It should be clear, concise, and meaningful. Instead of writing vague messages like “updated code” or “fix,” a proper commit message describes what was changed and why. For example: “Fixed login validation issue by adding email format check.” This makes it easier for other developers (and your future self) to understand the history of the project.
Commit messages typically follow a simple structure: a short summary line, optionally followed by a detailed description. Many teams follow conventions like starting with a verb (e.g., “Add,” “Fix,” “Update”) and keeping the summary under 50 characters.
Using good Git commit practices improves code readability, simplifies debugging, and helps in tracking progress over time. In professional environments, clean commit history is as important as clean code.
- Here’s a list of commonly used Git commands with short explanations:
???? Basic Commands
git init – Initialize a new Git repository
git clone <url> – Clone a repository from a remote source
git status – Check current status of files
git add <file> – Add file(s) to staging area
git add . – Add all files to staging
git commit -m "message" – Save changes with a message
???? Branching & Merging
git branch – List branches
git branch <name> – Create a new branch
git checkout <branch> – Switch to a branch
git checkout -b <branch> – Create and switch branch
git merge <branch> – Merge a branch into current branch
???? Remote Repositories
git remote add origin <url> – Connect to remote repo
git push origin <branch> – Push code to remote
git pull origin <branch> – Fetch & merge from remote
git fetch – Download changes without merging
???? Undo & History
git log – View commit history
git diff – Show changes between commits/files
git reset <file> – Unstage a file
git reset --hard – Reset all changes (⚠️ deletes changes)
git revert <commit> – Undo a commit safely
???? Stashing
git stash – Save changes temporarily
git stash pop – Apply stashed changes
???? Configuration
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
These are the most essential Git commands used in daily development.