Listen to this Post

Git is a powerful version control system used by developers worldwide. Below is a detailed breakdown of essential Git commands with practical examples.
1. `git add`
Prepares changes for committing by adding them to the staging area.
git add filename.txt Stage a single file git add . Stage all changes git add -u Stage only modified/deleted files
2. `git branch`
Manages branches in your repository.
git branch List all branches git branch new-feature Create a new branch git branch -d old-branch Delete a branch
3. `git config`
Customizes Git settings.
git config --global user.name "Your Name" git config --global user.email "[email protected]"
4. `git commit`
Saves changes with a message.
git commit -m "Initial commit" git commit --amend Modify the last commit
5. `git checkout`
Switches branches or restores files.
git checkout main Switch to 'main' branch git checkout -b new-branch Create & switch to a new branch git checkout -- file.txt Discard changes in a file
6. `git init`
Initializes a new Git repository.
git init Start a new repo in current directory
7. `git diff`
Shows changes between commits, branches, or files.
git diff Unstaged changes git diff --cached Staged changes git diff branch1..branch2 Compare two branches
8. `git stash`
Temporarily stores changes without committing.
git stash Save changes git stash pop Restore changes git stash list List all stashes
9. `git merge`
Combines changes from different branches.
git merge feature-branch Merge into current branch
10. `git push`
Uploads changes to a remote repository.
git push origin main Push to 'main' branch
11. `git clone`
Copies a remote repository.
git clone https://github.com/user/repo.git
12. `git status`
Displays repository status.
git status Show tracked/untracked files
13. `git pull`
Fetches and merges remote changes.
git pull origin main Update local repo
14. `git reset`
Undoes changes.
git reset --soft HEAD~1 Undo last commit, keep changes git reset --hard HEAD~1 Discard last commit & changes
15. `git remote`
Manages remote repositories.
git remote -v List remotes git remote add origin URL Add a new remote
You Should Know:
- Undoing Mistakes:
git reflog View all Git actions history git reset --hard COMMIT_ID Revert to a specific commit
-
Rebasing vs. Merging:
git rebase main Apply changes on top of main branch
-
Tagging Releases:
git tag -a v1.0 -m "Release 1.0" git push --tags
-
Finding Changes by Author:
git log --author="John"
-
Cleaning Untracked Files:
git clean -fd Force delete untracked files/dirs
What Undercode Say:
Git is essential for efficient version control. Mastering these commands improves collaboration and workflow. Advanced users should explore:
– Interactive Rebasing (git rebase -i)
– Submodules (git submodule)
– Hooks (.git/hooks/)
– Bisecting Bugs (git bisect)
For DevOps, combine Git with CI/CD tools like Jenkins or GitHub Actions.
Expected Output:
Sample Git Workflow git init git add . git commit -m "Initial commit" git remote add origin https://github.com/user/repo.git git push -u origin main
Prediction: Git will continue evolving with AI-powered commit suggestions and automated conflict resolution.
Relevant URL: Git Official Documentation
IT/Security Reporter URL:
Reported By: Parasmayur Git – Hackers Feeds
Extra Hub: Undercode MoN
Basic Verification: Pass ✅


