Listen to this Post
Mastering Git is crucial for developers working with version control. Git helps track changes, collaborate efficiently, and manage codebases seamlessly. Below is a detailed breakdown of essential Git commands, along with practical examples and best practices.
Basic Git Commands
1. `git init` – Initialize a new Git repository.
git init
2. `git clone` – Clone an existing repository.
git clone https://github.com/user/repo.git
3. `git status` – Check the status of your working directory.
git status
4. `git add` – Stage changes for commit.
git add filename.txt git add . Stage all changes
5. `git commit` – Commit staged changes.
git commit -m "Your commit message"
6. `git push` – Push changes to a remote repository.
git push origin main
7. `git pull` – Fetch and merge changes from a remote repository.
git pull origin main
Branching & Merging
8. `git branch` – List, create, or delete branches.
git branch List branches git branch new-branch Create a new branch git branch -d branch Delete a branch
9. `git checkout` – Switch between branches.
git checkout branch-name git checkout -b new-branch Create & switch
10. `git merge` – Merge branches.
git checkout main git merge feature-branch
11. `git rebase` – Reapply commits on top of another branch.
git rebase main
Undoing Changes
12. `git reset` – Unstage changes.
git reset HEAD filename.txt Unstage a file git reset --hard HEAD^ Discard last commit
13. `git revert` – Create a new commit that undoes previous changes.
git revert commit-hash
14. `git stash` – Temporarily save changes.
git stash git stash pop Reapply stashed changes
Remote Repositories
15. `git remote` – Manage remote repositories.
git remote -v List remotes git remote add origin URL Add a remote
16. `git fetch` – Download changes without merging.
git fetch origin
17. `git diff` – Compare changes.
git diff Unstaged changes git diff --cached Staged changes
You Should Know:
– `.gitignore` – Exclude files from tracking.
echo "node_modules/" >> .gitignore
- Aliasing Commands – Save time with shortcuts.
git config --global alias.co checkout git co branch-name Now works like git checkout
-
View Commit History – Use `git log` with formatting.
git log --oneline --graph
What Undercode Say
Git is a powerful tool for version control, but mastering it requires practice. Use these commands daily to streamline your workflow. For deeper learning, explore:
– Git Documentation
– GitHub Guides
Expected Output:
A well-structured Git workflow that enhances collaboration and code management.
(Note: WhatsApp/Telegram URLs removed as per instructions.)
References:
Reported By: Riyazsayyad Git – Hackers Feeds
Extra Hub: Undercode MoN
Basic Verification: Pass ✅



