By Karthik Santhosh
Git is a powerful tool for developers β not just for saving your code, but for managing versions, collaborating, and resolving issues like a pro. In this post, letβs walk through some essential and advanced Git commands that can boost your workflow.
1. π git diff
Purpose: Show changes between files, commits, or branches.
Use Case: Compare your working directory with the index or a previous commit.
git diff
2. π git log
Purpose: Display the full commit history.
Use Case: Track changes, find specific commits, or understand project history.
git log
3. π₯ git clone
Purpose: Clone a remote repository to your local machine.
git clone https://github.com/karthikio/24MCR050
4. β¬οΈ git pull
Purpose: Fetch and merge changes from the remote repo to your current branch.
git pull origin main
5. β¬οΈ git push
Purpose: Push your local commits to the remote repository.
git push origin main
6. π΅οΈ git blame
Purpose: Show who last modified each line of a file and when.
Use Case: Great for debugging or understanding change history.
git blame ML.txt
7. βοΈ Merge Conflicts (Concept)
Note: Merge conflicts happen when two branches modify the same part of a file.
To simulate a merge conflict:
git checkout -b new-branch
# Make changes, commit them
git checkout main
# Make conflicting changes
git merge new-branch
# Conflict occurs here
You'll need to manually resolve the conflict in the files and commit the resolution.
8. πΏ git branch
Purpose: List, create, or delete branches.
git branch # List branches
git branch feature # Create a branch
git branch -d feature # Delete a branch
9. π git checkout -b
Purpose: Create and switch to a new branch in one step.
git checkout -b advanced-git-commands
10. π .gitignore
Purpose: Tell Git which files or folders to ignore in version control.
Steps to set up:
- Create a
.gitignore
file in your root directory. - Add patterns of files or folders to ignore.
Example:
*.log
node_modules/
.env
No command is needed β Git will automatically skip tracking files that match the patterns.
π¦ Bonus: GitHub Repo
You can check out the repository related to this guide here:
π GitHub - 24MCR050
π‘ Final Thoughts
These Git commands may look simple, but mastering them gives you better control, cleaner workflows, and confidence when collaborating with teams. Whether you're debugging, exploring history, or working on features β Git's got your back.
If you liked this post, drop a β€οΈ or comment your favorite Git command below!
π§βπ» Written by Karthik Santhosh
Full-Stack Developer | React & Firebase | Open Source Learner
Top comments (0)